Missing '=' operator after key in hash literal

I have powershell 4.0 running on windows server 2012 R2 . I want to extract several files from the source folder to destination folder. I have the list of files in CSV template. When I ran the script I got an error like this: Missing '=' operator after key in hash literal. I don;t know what i am doing wrong. Here is my script:

##The external CSV template is like this:

Source_Target_folders
    "C:\Data_Files\fileone.$TodayDate" = "E:\DEV\_Datafiles\fileone_Extracted"       
    "C:\Data_Files\filetwo.$TodayDate" = "E:\DEV\_Datafiles\filetwo_Extracted"      
    "C:\Data_Files\filethree.$TodayDate" = "E:\DEV\_Datafiles\filethree_Extracted"      
    "C:\Data_Files\filefour.$TodayDate" = "E:\DEV\_Datafiles\filefour_Extracted"         
    "C:\Data_Files\filefive.$TodayDate" = "E:\DEV\_Datafiles\filefive_Extracted"

## Call the CSV

$ZipFiles  = Import-csv "c:\PowershellScript\ZipFileFolders.csv"

$ZipFilesAndFolders = @{$ZipFiles}

foreach ($KeyAndValue in $ZipFilesAndFolders.GetEnumerator())
   {
       $ZipFilePath = $KeyAndValue.Key
        $DestinationPath = $KeyAndValue.Value


        echo "-------------------------------------------"
        echo "start extracting"
        Get-ChildItem $ZipFilePath | % {& "E:\7-Zip\7za.exe" "x" $_.fullname "-o$DestinationPath"}        
       echo "Finish extracting $Dept_name"
       echo "--------------------------------------------"
  }      

What am I doing wrong? Please help

Parents Reply
  • Your .csv file sounds like .csv file but is not a .csv.

    Source_Target_folders
        "C:\Data_Files\fileone.$TodayDate" = "E:\DEV\_Datafiles\fileone_Extracted"       
        "C:\Data_Files\filetwo.$TodayDate" = "E:\DEV\_Datafiles\filetwo_Extracted"      

    Only one Header : Source_Target_folders

    Only one value : "C:\Data_Files\filetwo.$TodayDate" = "E:\DEV\_Datafiles\filetwo_Extracted"

    your .csv file must be like the following  : 

    SourceFile, TargetFolder

    C:\Data_Files\filetwo.$TodayDate, E:\DEV\_Datafiles\filetwo_Extracted  <=== these are files not folders

    Nota1 :  the comma (you can put ; if you want but when you'll import the .csv file don't forget -delimiter ";" depending how this .csv has been encoded)

    Nota2 : in you .csv file, the " separating each filed are not required.

    $ZipFiles  = Import-csv "c:\PowershellScript\ZipFileFolders.csv"

    $ZipFilesAndFolders = @{$ZipFiles}

    foreach ($KeyAndValue in $ZipFilesAndFolders.GetEnumerator())
       {
           $ZipFilePath = $KeyAndValue.Key
            $DestinationPath = $KeyAndValue.Value

    Nota3 : .Zip files are files not folders ! 

    Nota4 : the coding : Get-ChildItem work fine ... but for directory but it's a non-sense to use it with a file. It returns like Get-Item in this case.

    foreach ($file in $zipfiles)

    Expand-Archive -Path $file.SourceFile -DestinationPath  $file.DestinationFolder

    Write-verbose "Expanding $($file.Sourcefile) to $($file.DestinationFolder"

    (in PS >v5. WIth PS v4 theis cmdlet doesn't exist, use 7-zip is you want or .net class as you want)

    }

    Nota 5 : in a loop, call the current variable property you want

    Please note that in the loop, i'm calling $file.PropertyNamethatImLookingFor.

    In the .csv file there are 2 properties called SourceFile and DestinationFolder.

    Now it will be fine, and this could be run without any pb.

    Regards

    Oliv

Children