I have a script which downloads blobs from Azure Storage with PowerShell:
ForEach ($blob in $topBlobs) {
Write-Output "Downloading $blob.Name..."
Get-AzureStorageBlobContent -Blob $blob.Name `
-Container $ContainerName `
-Destination $officeFolder `
-Context $ctx -ErrorAction SilentlyContinue -Confirm:$false
Write-Output "Done."
}
How can I force it to answer NO no matter what? If I run it as is now from command line (.cmd file on Windows) it asks for a confirmation!
The -Confirm
switch is set to false by default so you omit it. You may see the confirmation dialog due to an existing file. You can bypass it by adding the -force
switch.
Okay, So since you don't want to overwrite the files you could do something like this:
$existingFiles = Get-childitem $officeFolder | Select-Object -ExpandProperty Name
ForEach ($blob in ($topBlobs | Where-Object Name -NotIn $existingFiles)) {
Write-Output "Downloading $blob.Name..."
Get-AzureStorageBlobContent -Blob $blob.Name `
-Container $ContainerName `
-Destination $officeFolder `
-Context $ctx
Write-Output "Done."
}