PowerShell is missing the terminator: "
Asked Answered
S

9

65

I have the following script code

#[string]$password = $( Read-Host "Input password, please" )
param (
    [string]$ReleaseFile = $(throw "-ReleaseFile is required"),
    [string]$Destination = $(throw "-Destination is required")
)
 
function unzipRelease($src, $dst)
{
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($src)
    foreach($item in $zip.items())
    {
        $shell.Namespace($dst).copyhere($item)
    }
}

#  .\deployrelease.ps1 -ReleaseFile ".\deploy.zip" -Destination "."

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

I run the script with: .\deployrelease.ps1 -ReleaseFile ".\deploy.zip" -Destination "."

But I keep getting this:

PS C:\Users\Administrator\Documents\Tools> .\deployrelease.ps1 -ReleaseFile ".\deploy.zip" -Destination
The string starting:
At C:\Users\Administrator\Documents\Tools\deployrelease.ps1:19 char:16
+ unzipRelease â? <<<< "Src '$ReleaseFile' -Dst '$Destination'
is missing the terminator: ".
At C:\Users\Administrator\Documents\Tools\deployrelease.ps1:19 char:55
+ unzipRelease â?"Src '$ReleaseFile' -Dst '$Destination' <<<<
    + CategoryInfo          : ParserError: (Src `'$ReleaseF...'$Destination`':String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

I couldn't find the fix as I do not see any problem.

Any help?

Spleen answered 20/12, 2013 at 15:26 Comment(1)
What editor are you using?Wholesale
W
155

Look closely at the two dashes in

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

This first one is not a normal dash but an en-dash (&ndash; in HTML). Replace that with the dash found before Dst.

Whatever answered 20/12, 2013 at 15:31 Comment(0)
H
17

In my specific case of the same issue, it was caused by not having the Powershell script saved with an encoding of Windows-1252 or UFT-8 WITH BOM.

Hutton answered 23/6, 2020 at 8:55 Comment(1)
Same issue here. I had some unicode characters in the script file, which was saved with an encoding of UTF-8 without BOM. Adding the BOM solved the issue.Adjoining
E
7

This can also occur when the path ends in a '' followed by the closing quotation mark. e.g. The following line is passed as one of the arguments and this is not right:

"c:\users\abc\"

instead pass that argument as shown below so that the last backslash is escaped instead of escaping the quotation mark.

"c:\users\abc\\"

Earthquake answered 28/6, 2020 at 13:47 Comment(0)
S
4

In your script, why are you using single quotes around the variables? These will not be expanded. Use double quotes for variable expansion or just the variable names themselves.

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

to

unzipRelease –Src "$ReleaseFile" -Dst "$Destination"
Seftton answered 20/12, 2013 at 16:4 Comment(0)
U
3

if you're using RHEL, try replacing " with ' - this fixed the error for me

cheers

Underlaid answered 29/8, 2022 at 11:9 Comment(0)
C
2

This error will also occur if you call .ps1 file from a .bat file and file path has spaces.

The fix is to make sure there are no spaces in the path of .ps1 file.

Confabulation answered 6/12, 2018 at 22:44 Comment(0)
D
1

You can spot the error when using @ prefix/suffix with multiline string while you actually have the ending suffix "@.

My script looked like that:

Add-Type @"
    public class SomeClass {
        ...
    }"@

and I still got the: The string is missing the terminator: "@.

Message was misleading because all I needed to do was to put "@ into new line without any leading space:

Add-Type @"
    public class SomeClass {
        ...
    }
"@
Diffractive answered 5/3, 2021 at 13:41 Comment(0)
A
0

my folder contained ' symbol. After I removed it, the issue resolved.

Anurag answered 4/3, 2021 at 9:56 Comment(0)
W
0

This error comes mostly when you dont put the power shell variable under double quotes "variable_name"

Woollen answered 5/2 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.