PowerShell script error: there is no terminator in the line:

Incredibly simple powershell script ...

#Server side storage copy $SourceStorageAccount = "myStorageAccount" $SourceStorageKey = "myKey" $SourceStorageContext = New-AzureStorageContext –StorageAccountName $SourceStorageAccount -StorageAccountKey $SourceStorageKey 

with an error

In E: \ DeploymentScripts \ Storage \ Test.ps1: 6 char: 51 + ... geContext - StorageAccountName $ SourceStorageAccount -StorageAccount ... + ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Line missing terminator: ". + CategoryInfo: ParserError: ( :) [], ParseException + FullyQualifiedErrorId: TerminatorExpectedAtEndOfString

The weirdest part is if I copy and paste the contents of the ps1 file into the PowerShell command line, it works fine !? What's happening?

Obviously, I deleted the name and key of the storage container, you will need to assign your own name to the Azure storage account and the api key to replicate it.

EDIT: Screenshot of a script edited in Notepad ++ with all visible characters ...

Screenshot of a script edited in Notepad ++ with all visible characters

+2
source share
2 answers

It looks like this question .

When you copy cmdlets from the Internet, there may be special characters. I suggest you copy the cmdlets to Notepad, and then copy to PowerShell.

It is useful to use cat filename.ps1 in the terminal, which you can determine which characters are bad, this is not obvious in the editor.

+3
source

In this way, parts of the code are copied and pasted from websites with non-standard barcode characters. It was easier for me to see the characters when you use the cat command from the powershell command line to display the file

Here is a screenshot of what it looks like in powershell: - enter image description here

+1
source

All Articles