Create a SQL Server Credential for Accessing Azure Blob Storage

Prerequisites:

  • The SqlServer PowerShell module must be installed.
    • Run Install-Module -Name SqlServer if you need to install it…
create-credential.ps1
 1import-module SqlServer
 2
 3$storageAccount = "<StorageAccountName>"  #replace this with your Azure storage account name
 4$storageKey = "<StorageAccountKey>"  #replace this with one of your Azure storage account keys
 5$secureString = convertto-securestring $storageKey  -asplaintext -force  
 6$credentialName = "BlobStorageCredential" #give the credential a name - you'll reference it again later (in other scripts, for example)
 7
 8cd SQLServer:\SQL\$env:COMPUTERNAME
 9
10$instances = Get-ChildItem
11$instances | new-sqlcredential -Name $credentialName -Identity $storageAccount -Secret $secureString