Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell is missing the terminator: "

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?

like image 414
CoolStraw Avatar asked Dec 20 '13 15:12

CoolStraw


People also ask

How do you escape a single quote in PowerShell?

Any single quote characters would not need to be escaped. Of course, the situation is reversed if the PowerShell string is quoted with single quotes. In that case, single quote characters cannot be escaped with the backtick "`", so you must double the embedded single quotes (replace any embedded ' characters with '').

How do you escape double quotes in PowerShell?

You can either enclose your string in single quotes or escape the double quotes with a symbol called a backtick.

How do I comment in a PowerShell script?

You can type a comment symbol ( # ) before each line of comments, or you can use the <# and #> symbols to create a comment block. All the lines within the comment block are interpreted as comments. Each section of comment-based Help is defined by a keyword and each keyword is preceded by a dot ( . ).


3 Answers

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.

like image 73
Tim Pietzcker Avatar answered Oct 20 '22 02:10

Tim Pietzcker


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.

like image 45
Morten Nørgaard Avatar answered Oct 20 '22 01:10

Morten Nørgaard


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\\"

like image 6
vikas pachisia Avatar answered Oct 20 '22 03:10

vikas pachisia