Skip to content

Instantly share code, notes, and snippets.

@marckean
Created September 23, 2016 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/4d4ea168c3ba773e74b5e7c950311182 to your computer and use it in GitHub Desktop.
Save marckean/4d4ea168c3ba773e74b5e7c950311182 to your computer and use it in GitHub Desktop.
workflow Shutdown_VM
{
$Cred = Get-AutomationPSCredential -Name "Credential_Name"
$tenant = Get-AutomationVariable -Name "tenant"
Login-AzureRmAccount -Credential $Cred -ServicePrincipal -TenantId $tenant
$subscription = Get-AutomationVariable -Name "subscription"
Select-AzureRmSubscription -SubscriptionName $subscription
$VMs = Get-AzureRmVM | where {$_.Name -match 'Virtual_Machine_Name'}
ForEach -Parallel ($VM in $VMs)
{
Stop-AzureRmVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName -Force
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment