When iam trying to create lock using powershell Azure automation runbook by using below script
New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName resorcename -LockNotes Protection Auto created by Azure Backup -ResourceType Microsoft.Storage/storageAccounts -Force
error getting: A positional parameter cannot be found that accepts argument 'Auto' Source: https://learn.microsoft.com/en-us/powershell/module/az.resources/new-azresourcelock?view=azps-9.1.0
Try the following command
New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName resorcename -LockNotes "Protection Auto created by Azure Backup" -ResourceType Microsoft.Storage/storageAccounts -Force
Hope this helps!
CodePudding user response:
I tried in my environment and same error:
Commands:
New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName rsname -LockNotes Protection Auto created by Azure Backup -ResourceType Microsoft.Storage/storageAccounts -Force
Initially i have tried same command:
After I changed the Lock notes in String its worked.
Commands:
New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName rsname -LockNotes "Protection Auto created by Azure Backup" -ResourceType Microsoft.Storage/storageAccounts -Force
Reference: New-AzResourceLock (Az.Resources) | Microsoft Learn