Home > Mobile >  New-AzResourceLock: A positional parameter cannot be found that accepts argument
New-AzResourceLock: A positional parameter cannot be found that accepts argument

Time:11-22

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'enter image description here enter image description here 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: enter image description here

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

enter image description here

Reference: New-AzResourceLock (Az.Resources) | Microsoft Learn

  • Related