Allan Xu
Allan Xu

Reputation: 9298

Options to make Set-AzureStorageBlobContent do not overwrite a blob if already exists

I use the PowerShell command line below to upload a file to a blob storage and overwrite if already exists:

Set-AzureStorageBlobContent -Confirm:$false -Force

It works well.

For another scenario, I need to do opposite and make sure Set-AzureStorageBlobContent does not overwrite blobs if already exist.

I know that I can use the logic explained here:

How to check if a blob already exists in Azure blob container using PowerShell

However, I am hoping that there is a simpler option in PowerShell.

I expect there should be a way to auto-answer "No" to Powershell's -Confirm prompt.

Is there any PowerShell technique that I can use here?

Upvotes: 1

Views: 3137

Answers (1)

postanote
postanote

Reputation: 16096

The -confirm prompts specific goal is to force a user to respond, or exempt the user from responding.

# Throw prompt
Remove-Item -Path:'D:\Temp\input - Copy.txt' -Confirm:$true

# Don't throw prompt
Remove-Item -Path:'D:\Temp\input - Copy.txt' -Confirm:$false -Verbose

VERBOSE: Performing the operation "Remove File" on target "D:\Temp\input - Copy.txt".

The discussion you point to is prudent. There is no auto answer to many object interactions, you have to do what the discussion highlights when such options don't exist.

Or as just an if single simple if or try..catch statement.

if((Test-Path 'D:\temp\aliases.htm') -eq $true){
    'Do nothing'
}


if((Test-Path 'D:\temp\aliases.htm') -eq $false){
    'do something'
}

What are you considering, simpler than those examples?

Upvotes: 1

Related Questions