Azure “GoUp and Goto Sleep” Maintenance Scripts


Azure “GoUp and Goto Sleep” Maintenance Scripts
azure1
Below two simple scripts to Startup & Shutdown Azure Virtual Machines; you can use these samples scripts with “Azure Scheduler Agent” to reduce costs using “pay for use” Azure subscriptions.
** STARTUP VM **
workflow startup-vm
{
$Cred = Get-AutomationPSCredential -Name ‘My Scheduler’
Add-AzureAccount -Credential $CredInlineScript
{

    Select-AzureSubscription -SubscriptionName “My Subscription Name”

$VMS = Get-AzureVM

    foreach($VM in $VMS)
{
$VMName = $VM.Name
Start-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name
Write-Output “Shutting down VM :  $VMName ”
}
}
}
** SHUTDOWN VM **
workflow shutdown-vm
{
$Cred = Get-AutomationPSCredential -Name ‘My Scheduler’
Add-AzureAccount -Credential $CredInlineScript
{

    Select-AzureSubscription -SubscriptionName “My Subscription Name”

$VMS = Get-AzureVM

    foreach($VM in $VMS)
{
$VMName = $VM.Name
Stop-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name -Force
Write-Output “Shutting down VM :  $VMName ”
}
}
}
you are welcome !
Annunci