Skip to content

Instantly share code, notes, and snippets.

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 brendan-rice/ff81835c4a59cbc06b537489da75f1d4 to your computer and use it in GitHub Desktop.
Save brendan-rice/ff81835c4a59cbc06b537489da75f1d4 to your computer and use it in GitHub Desktop.
Powershell script for starting Azure VMs on a schedule in an Azure Automation runbook
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