skip to Main Content

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 Hope you can help me with a problem trying to execute a script block, Thanks in Advance.

3

Answers


  1. The lockNotes parameter must be between quotes.
    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!

    Login or Signup to reply.
  2. You should either have string variabel that contains Lock Notes or put the lock notes string in quotes,

    $myLocknotes = "Protection Auto created by Azure Backup"
    New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName resorcename -LockNotes myLocknotes  -ResourceType Microsoft.Storage/storageAccounts -Force
    

    Or

    New-AzResourceLock -LockName test -LockLevel CanNotDelete -ResourceGroupName rg -ResourceName resorcename -LockNotes "Protection Auto created by Azure Backup" -ResourceType Microsoft.Storage/storageAccounts -Force
    
    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search