[powershell] 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?

This question is related to powershell powershell-2.0 powershell-3.0

The answer is


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.


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"

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.


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


Examples related to powershell

Why powershell does not run Angular commands? How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? How to print environment variables to the console in PowerShell? Check if a string is not NULL or EMPTY The term 'ng' is not recognized as the name of a cmdlet VSCode Change Default Terminal 'Connect-MsolService' is not recognized as the name of a cmdlet Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet Change directory in PowerShell

Examples related to powershell-2.0

Extract the filename from a path Out-File -append in Powershell does not produce a new line and breaks string into characters Using PowerShell to remove lines from a text file if it contains a string PowerShell The term is not recognized as cmdlet function script file or operable program Can't install nuget package because of "Failed to initialize the PowerShell host" Powershell script to see currently logged in users (domain and machine) + status (active, idle, away) How to export data to CSV in PowerShell? powershell is missing the terminator: " PowerShell script to check the status of a URL How to upgrade PowerShell version from 2.0 to 3.0

Examples related to powershell-3.0

Check if a file exists or not in Windows PowerShell? Executing a batch file in a remote machine through PsExec Powershell get ipv4 address into a variable How can you test if an object has a specific property? PowerShell To Set Folder Permissions Using PowerShell to remove lines from a text file if it contains a string Powershell script to see currently logged in users (domain and machine) + status (active, idle, away) powershell is missing the terminator: " How to upgrade PowerShell version from 2.0 to 3.0 Copy-item Files in Folders and subfolders in the same directory structure of source server using PowerShell