Created
December 27, 2014 11:22
-
-
Save sitereactor/d49c360b59a34ef18939 to your computer and use it in GitHub Desktop.
Powershell script for starting 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 Start-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 | |
Start-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