0

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

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Could you please confirm if you want to retrive the sas token creation date ,Other then that you are getting all the details. – AjayKumarGhose Apr 20 '22 at 03:51
  • Could you please provide the command that you have tried so far – AjayKumarGhose Apr 20 '22 at 04:14
  • Have you checked the Az modules for related commands? [Az storage docs](https://learn.microsoft.com/en-us/powershell/module/az.storage/?view=azps-7.4.0#storage) – Todd Apr 20 '22 at 04:20
  • For SAS token creation I used below command New-AzStorageAccountSASToken -Service File -ResourceType Container -Permission "rwdl" -ExpiryTime (Get-Date).AddDays(7) -Context $StorageContext – Rajasekhar M Apr 20 '22 at 20:33
  • @Todd, Yes I gone through the Az storage docs link. I have found the command to create SAS Token but not for the Connection String and File Service SAS URL. As reffered in the screen shot I would like have All 3 ( SAS Token, Connection String and File Service SAS URL) through Power Shell Commands. I could get the SAS Token with New-AzStorageAccountSASToken, Now I need other 2. So looking for the Power Shell command to get those. – Rajasekhar M Apr 20 '22 at 23:17
  • If the features haven't yet made their way into the Az modules, you may find what you need in the [REST API](https://learn.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api). You can use `Invoke-AzRestMethod`, `Get-AzResource`, etc., to interact with it. – Todd Apr 21 '22 at 01:51

1 Answers1

0

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:-

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15