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:

    "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

  • This '=' is an assignment operation, not a comparison operator. For that you use '-eq' Echo is a batch file thing, and a alias in PS, do use that use the real cmdlet names always. Also, Don't use echo aka Write-Host unless you need to use color. Output results to the screen is the PS default. So, echo / Write-Host is redundant. If those items in the csv are source and destination, they must be split into two variables in order to be properly passed / used.

Reply Children