azureazure-storageazure-powershellazureportal

Azure Run Command Error: The string is missing the terminator: "


I'm attempting to map an Azure Storage Account file share via Run Command in the portal:

$storageAccountKey = 'key'
$storageAccountName = 'account'
$securePass = $storageAccountKey | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $storageAccountName,$securePass

New-PSDrive -Credential $creds -Name Z -PSProvider FileSystem -Root '\\account.file.core.windows.net\files01' > $null

I'm getting the missing terminator error:

At C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\Downloads\script9.ps1:6 char:15
+ files01"
+        ~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

I've run the command with single-quotes, double-quotes, escaped slashes in the path... I'm left scratching my head trying to figure out where the issue lies. Am I using commands for a version of PS that the script isn't running on?

The code is copied from VS Code into the browser. Unless VS Code is encoding text in an odd way, I'm presuming it is just simple, plain text that I'm copying over.

I ran the same code locally on the VM (in PS 7.4) and it succeeded. I did have to remove all other mapped shares from the same storage account otherwise it would throw the error regarding multiple connections to a server or shared resource.... Might that be the issue in some obscure, roundabout way?


Solution

  • Azure Run Command Error: The string is missing the terminator: "

    Check the version of PowerShell used by Run Command:

    $PSVersionTable | Out-String | Write-Host
    

    In my environment it shown 5.1

    Name                           Value                                                                                   
    ----                           -----                                                                                   
    PSVersion                      5.1.22621.4391                                                                          
    PSEdition                      Desktop                                                                                 
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
    BuildVersion                   10.0.22621.4391                                                                         
    CLRVersion                     4.0.30319.42000                                                                         
    WSManStackVersion              3.0                                                                                     
    PSRemotingProtocolVersion      2.3                                                                                     
    SerializationVersion           1.1.0.1
    

    enter image description here

    You can use the below script that will map the Azure Storage Account file share via Run Command in the portal.

    Script:

    $storageAccountName = 'venkat326123'
    $storageAccountKey = 'zzzz'
    $shareName = 'share1'
    $securePass = $storageAccountKey | ConvertTo-SecureString -AsPlainText -Force
    $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $storageAccountName,$securePass
    
    New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\$storageAccountName.file.core.windows.net\$shareName" -Credential $creds
    

    Output:

    Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
    ----           ---------     --------- --------      ----                                               ---------------
    Z                                      FileSystem    \\venkat326123.file.core.windows...
    

    enter image description here

    Reference:

    windows S2022 net use cannot accept Azure storage key because it starts with slash AND sshd limitations - Stack Overflow by Buzz Moschetti