Advertisement
RJSN

Set-AzureRMLock

Jul 12th, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.         .NOTES
  3.         #------------------------------------------------------------------------------------------
  4.         # Date         : 12-07-2017
  5.         # Script name      : Set-AzureRMLock.ps1
  6.         # Description      : Set locks on resources for accidental deletion
  7.         # Created by       : Ralph Jansen
  8.         # Extra module     :
  9.         # Copyright        : ©2017 Ralph Jansen, all rights reserved.
  10.         # History          : RJA 12-07-2017 Initial version
  11.         #
  12.         #------------------------------------------------------------------------------------------
  13.        
  14.         .DESCRIPTION
  15.         Set locks on resources for accidental deletion
  16.        
  17. #>
  18.  
  19. Start-Transcript -Path '$env:TMP\Set-AzureRMLock.log'  -Force
  20. Write-Verbose -Verbose "Script started..."
  21.  
  22. Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
  23.  
  24. Login-AzureRmAccount -SubscriptionName "<Subscription Name>"
  25.  
  26. # Removing resource locks
  27. Get-AzureRmResourceLock | Remove-AzureRmResourceLock -Force
  28.  
  29. # Setting resource locks
  30. $Resource = Find-AzureRmResource
  31.  
  32. foreach ($item in (Find-AzureRmResource))
  33. {
  34.    Set-AzureRmResourceLock -resourcename $item.ResourceName -ResourceType $item.ResourceType -resourcegroup $item.ResourceGroupName -LockName "Lock" -LockLevel CanNotDelete -LockNotes "Locked for accidental deletion" -Force
  35. }
  36.  
  37. Stop-Transcript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement