Forum Discussion
MarkBovenzi
Feb 22, 2024Copper Contributor
PowerShell command trying to grab files from External Blob Storage
Hi there,
We have a ERP company that backsup a Database, and I want to setup a script to automatically grab those backup files from their Azure storage. I wrote a script to communicate with the storage with the secret key, and grab the .backpac files and store them locally on our SQL desktop. Once I am successful there, I am going to setup a Task Scheduler to do this automatically. But, when I try to run the script, I get an argument error. It's probably something simple, but thought I'd ask. Secret Key, Account name and and database replaced with "xxxxxxx"
$firstBlob = az storage blob list --account-key xxxxxxxxxx== --account-name xxxxxxx -c xxxxxx |
ConvertFrom-Json |
Select-Object name, @{Name="lastModified"; Expression={$_.properties.lastModified}}, properties |
Sort-Object -Property lastModified -Descending |
Select-Object -First 1
# Check if $firstBlob is not null (i.e., there are blobs found)
if ($firstBlob) {
Write-Host $firstBlob.name "Found! Downloading..."
az storage blob download --account-key xxxxx== --account-name xxxxx-c xxxxxx--name $firstBlob.name --file ./backup.bacpac
} else {
Write-Host "No backups found."
}
az : ERROR: argument --name/-n: expected one argument
At C:\Users\Administrator\Desktop\Azure.ps1:10 char:5
+ az storage blob download --account-key xxxxxxxxx...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR: argument...ed one argument:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Examples from AI knowledge base:
az storage blob download --account-key 00000000 --account-name myaccount --container-name mycontainer --file file.txt --name myblob
Downloads a blob to a file path, with automatic chunking and progress notifications. (autogenerated)
az storage blob download --account-name myaccount --container-name mycontainer --file file.txt --name myblob
Downloads a blob to a file path, with automatic chunking and progress notifications. (autogenerated)
https://docs.microsoft.com/en-US/cli/azure/storage/blob#az_storage_blob_download
Read more about the command in reference docs
- LainRobertsonSilver Contributor
Hi, Mark.
I know precisely nothing about the az command, however, it seems to be complaining about the --name parameter.
Try this format instead:
--name ($firstBlob.name)
Cheers,
Lain