Created
December 27, 2014 11:20
-
-
Save sitereactor/2a4886a39395c9656f1c to your computer and use it in GitHub Desktop.
Powershell script for stopping Azure VMs on a schedule in an Azure Automation runbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
workflow Stop-AzureVMsOnSchedule { | |
param( | |
# The name of the VM(s) to start on schedule. Can be wildcard pattern. | |
[Parameter(Mandatory = $true)] | |
[string]$VMName, | |
# The service name that $VMName belongs to. | |
[Parameter(Mandatory = $true)] | |
[string]$ServiceName, | |
# The name of the subscription. | |
[Parameter(Mandatory = $true)] | |
[string]$SubName, | |
# The name of the OrgCredUser. | |
[Parameter(Mandatory = $true)] | |
[string]$PsUserName | |
) | |
# Specify Azure Subscription Name | |
$Cred = Get-AutomationPSCredential -Name $PsUserName | |
# Connect to Azure | |
Add-AzureAccount -Credential $Cred | |
Select-AzureSubscription -SubscriptionName $SubName | |
$vm = Get-AzureVM -ServiceName $ServiceName -Name $VMName | |
Stop-AzureVM -ServiceName $vm.ServiceName -Name $vm.Name -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment