Missing '=' operator after key in hash literal.

Hi All,

I am running powershell version 4 on windows 2012 server.

I am getting below error, please advise as to what i am making mistake.

At C:\cas\fc5.ps1:17 char:5
+ Copy-Item -Path $item.FullName -Destination '($to+($item.FullName).su ...
+ ~
Missing '=' operator after key in hash literal.
At C:\cas\fc5.ps1:17 char:5
+ Copy-Item -Path $item.FullName -Destination '($to+($item.FullName).su ...
+ ~
The hash literal was incomplete.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral

Copy item is only giving error, not sure what mistake i am doing.

Below is the code

$path = "\\Source\c$\Vulnerability"

$to = "\\Destination\c$\Vulnerability\"
$items = Get-ChildItem -Path $path -Include '*x64*' -recurse
$array = New-Object System.Collections.ArrayList #Array is needed for display to work
foreach ($item in $items)
"Name File" = $item.name
# "Client Number" = $item.name.Substring(0,8)
"Path" = $item.FullName
"Child" = ($item.FullName).substring($path.length+1,$item.Fullname.length-$item.name.length-$path.length-2) # child path
"itemlength"= $item.Fullname.length #item.length-gives size of the file & item.name.length - gives file name length
"destipath" = ($to+($item.FullName).substring($path.length+1,$item.Fullname.length-$item.name.length-$path.length-2))
"test" = ($item.FullName).substring($path.length+1,$item.Name.length+10)
Copy-Item $item.FullName -Destination '($to+($item.FullName).substring($path.length+1,$item.Fullname.length-$item.name.length-$path.length-2))'
}) | Out-null

  • If you are doing this in the ISE or VSCode, those editors specifically show you where the error is as well, you need to run the code to see most errors. If you are using another editor that does not show you this, then yes you'd have to run the code to see such errors. The PowerShell ISE is built into PowerShell v3 - v5x, if you don't see it, then you have to enable it,  otherwise install VScode Editor for PowerShell development.

    1 - Note your array declaration is not correct.
    2 - Your ForEach loop is not properly closed.
    3 - Your Copy-Item line is not valid. Opening this in the ISE or VScode, via color syntax coding features, will highlight your obvious errors. Dotted notation, is white, not any other color.
    4 - Properly indenting your code will also show you such syntax issues, and VScode provides code formatters to do it automatically for you.
    5 - Copy-Item is a file system thing, and that destination must evaluate to a a real UNC path with a filename. What you have does not.

Reply Children
No Data