Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell script error: the string is missing the terminator:

Incredibly simple powershell script...

#Server side storage copy

$SourceStorageAccount = "myStorageAccount"
$SourceStorageKey = "myKey"

$SourceStorageContext = New-AzureStorageContext –StorageAccountName $SourceStorageAccount -StorageAccountKey $SourceStorageKey

fails with the error

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

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

Obviously I have removed my storage container name and key, you will need to assign your own Azure storage account name and api key to replicate it.

EDIT: A screen shot of the script edited in Notepad++ with all characters visible...

A screen shot of the script edited in Notepad++ with all characters visible

like image 578
Mick Avatar asked May 04 '17 07:05

Mick


1 Answers

So parts of the code are copied and pasted from websites which have non-standard dash characters. I found it easier to see the characters when you use the cat command from the powershell command line to list the file

Here's a screenshot of what it looks like listed in the powershell:- enter image description here

like image 98
Mick Avatar answered Sep 18 '22 12:09

Mick