-ConnectingString error New-azstoragecontext

ALEXNOEL 1 Reputation point
2023-01-05T03:27:05.23+00:00

Hi everyone,
Newbie here.
I am confused why i have this error when creating new-azstoragecontext -connectingstring. I got this error.

PS E:\afs> $AzCont = New-AzStorageContext -ConnectionString $ConString

New-AzStorageContext : Settings must be of the form "name=value".

  • $AzCont = New-AzStorageContext -ConnectionString $ConString
  • CategoryInfo : CloseError: (:) [New-AzStorageContext], FormatException
  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet.NewAzureStorageContext

Below is my script:

$FilePath = "E:\Dodz.txt"

$ConnectionString = Get-Content $FilePath | ConvertTo-SecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ConnectionString)
$ConString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

$AzCont = New-AzStorageContext -ConnectionString $ConString

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. risolis 8,701 Reputation points
    2023-01-05T04:25:44.043+00:00

    Hello @AlexisNoelHynson-4418

    Thank you for posting this concern on this community space.

    I am wondering if you have read the following documents below:

    https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal

    Furthermore, I am pasting an image where to find the connection-strings shown before.

    276318-image.png

    Let me know if that was useful but if not, I can keep assisting you further.

    Looking forward to your feedback,

    Cheers,

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. ALEXNOEL 1 Reputation point
    2023-01-06T02:22:08.037+00:00

    Hi @risolis , I managed to connectstring using the storage account key. But not sure if this is correct as i have another error. As shown below.

    PS E:\>

    $FilePath = "E:\Dodz.txt"

    $AzureFile01 = "autododz-fs"

    $AzRepPathINVENT = "DodzLogs\INVENT"

    $ConnectionString = Get-Content $FilePath | ConvertTo-SecureString

    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ConnectionString)

    $ConString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

    $AzCont = New-AzStorageContext -ConnectionString $ConString

    PS E:\> $AzCont

    StorageAccountName : ABCDEFG01

    BlobEndPoint : https://afsautomations.blob.core.windows.net/

    TableEndPoint : https://afsautomations.table.core.windows.net/

    QueueEndPoint : https://afsautomations.queue.core.windows.net/

    FileEndPoint : https://afsautomations.file.core.windows.net/

    Context : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext

    Name :

    StorageAccount : DefaultEndpointsProtocol=https;AccountName=afsautomationssa;AccountKey=[key hidden]

    TableStorageAccount : DefaultEndpointsProtocol=https;AccountName=afsautomationssa;AccountKey=[key hidden]

    Track2OauthToken :

    EndPointSuffix : core.windows.net/

    ConnectionString : DefaultEndpointsProtocol=https;AccountName=ABCDEFG01;AccountKey=adfadfasdgasgasgadgafgafgafgafgafgafgafgafgafsgafsgasfgafsgafe==

    ExtendedProperties : {}

    PS E:\>

    $Entires = Get-AzStorageFile -ShareName $AzureFile01 -Path $AzRepPathINVENT -Context $AzCont | Get-AzStorageFile

    foreach ($entry in $Entires.ShareFileClient) {
    Get-AzStorageFileContent -Context $AzCont -ShareName $AzureFile01 -path $entry.path -Destination ('\SERVER01\rawdata\' + $entry.name) -Force
    }

    I got this ERROR below:

    Get-AzStorageFile : An error occurred while sending the request.

    At line:2 char:12

    $Entires = Get-AzStorageFile -ShareName $AzureFile01 -Path $AzRepPathIN ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo : CloseError: (:) [Get-AzStorageFile], StorageException

    FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.GetAzureStorageFile

    PS E:\>

    0 comments No comments