Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Azure “GoUp and Goto Sleep” Maintenance Scripts

$
0
0
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 !


Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>