Search code examples
azurepowershellazure-devopsazure-powershellazure-cli

How to extract Connection String and File Service SAS URL from Azure PowerShell/ Azure CLI?


I am working on Powershell script that could extract Azure Storage Container details which includes SAS Token, Connection String, Expiry dates and File Service SAS URL. But I don't see any command to extract those details other than the SAS Token creation.

Could you please suggest the ways to extract those details through powershell or Azure Cli?

enter image description here


Solution

  • AFAIK,Using New-AzStorageAccountSASToken while we generate storage account sas token, will get the output of sas token only not connection string and blob service uri etc.

    This provide the following parameter:

    New-AzureStorageAccountSASToken
       -Service <SharedAccessAccountServices>
       -ResourceType <SharedAccessAccountResourceTypes>
       [-Permission <String>]
       [-Protocol <SharedAccessProtocol>]
       [-IPAddressOrRange <String>]
       [-StartTime <DateTime>]
       [-ExpiryTime <DateTime>]
       [-Context <IStorageContext>]
       [-DefaultProfile <IAzureContextContainer>]
       [<CommonParameters>]
    

    As shown below:

    enter image description here

    To extract the connection string of our storage account we can use the below cmd :

    az storage account show-connection-string --name MySA --resource-group MyRG --subscription MySubscription
    

    enter image description here

    To extract the blob service url we can use the below cmd :

     az storage blob generate-sas -c containername -n myfile.json --permissions r --expiry 2018-01-01T00:00:00Z --full-uri
    

    enter image description here

    For more information please refer the below links:-