How to Setup and Configure Microsoft Azure Automation Runbooks

Published Feb 16 2019 03:43 AM 246 Views
First published on TECHNET on Jun 06, 2016

~ Rupanter Chhabra | Microsoft Support Engineer

UPDATED 06/13/2016: Azure Automation has a new way to connect with Azure ARM resources and soon will also support a new way to connect with Azure Classic resources.  See this article for more information: https://azure.microsoft.com/en-us/documentation/articles/automation-sec-configure-azure-r...

=====

Hi everyone, we get a lot of questions regarding Azure Automation so I thought I’d take a few minutes and walk through an example of how to get everything set up, how to import a Runbook and then schedule a published workflow. In this particular example I’ll demonstrate how to configure Azure Automation to start/stop ARM virtual machines, however the general process can be used for a variety of tasks.

To get started, we first need to create an Azure Active Directory user that we can use for automation:

1. Select Active Directory :

This will forward you to Classic portal.

2. Click ADD USER :

3. Add the appropriate account information:

4. Next we need to select a role so that we’ll have the proper rights to access the virtual machines and the subscription.

NOTE Do not enable Multifactor Authentication.

Get your temporary password:

5. Now we need to allow this Azure Active Directory user to manage the Azure subscription:

6. We need to be sure that we change the temporary password so here are the steps:

  • a. Start Internet Explorer. If you’re currently logged, be sure you log out of your current Azure Account.
  • b. Log in to Azure by using the .onmicrosoft.com account that we created earlier (the Active Directory User account).
  • c. You will now be prompted to change the user’s password.

7. Now we need to create the Azure Automation account. Start by selecting Automation Accounts :

Click on Add for a new Automation Account:

Add your Automation Account name and select Resource Group (New) to create a new one.

8. Next we need to add ASSETS :

Add the following:

  • The Automation credential asset called AzureCredential that contains the Azure AD user credential (the .onmicrosoft.com account that we created earlier).
  • The Automation variable asset called AzureSubscriptionId that contains the Azure subscription.

First we add Credential :

Then we need to add a Variable which contain our Azure Subscription ID:

Now we have all needed Assets.

9. Next we need to select Runbooks and import the needed Runbooks from the gallery:

Select Start Azure ARM VMs:

Import:

Select Edit :

The script will look like this after removing the ASM code. This is the Runbook from the Gallery:

workflow Shutdown-Start-VMs-By-Resource-Group1
{
Param
(
[Parameter(Mandatory=$true)]
[String]
$AzureResourceGroup,
[Parameter(Mandatory=$true)]
[Boolean]
$Shutdown
)
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$CredentialAssetName = "AzureCredential";
#Get the credential with the above name from the Automation Asset store
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
}
#Connect to your Azure Account
Add-AzureRmAccount -Credential $Cred
##Add-AzureAccount -Credential $Cred  ##As we are doing it for ARM Virtual Machines.
if($Shutdown -eq $true){
Write-Output "Stopping VMs in '$($AzureResourceGroup)' resource group";
}
else{
Write-Output "Starting VMs in '$($AzureResourceGroup)' resource group";
}
#ARM VMs
Write-Output "ARM VMs:";
Get-AzureRmVM -ResourceGroupName $AzureResourceGroup | ForEach-Object {
if($Shutdown -eq $true){
Write-Output "Stopping '$($_.Name)' ...";
Stop-AzureRmVM -ResourceGroupName $AzureResourceGroup -Name $_.Name -Force;
}
else{
Write-Output "Starting '$($_.Name)' ...";
Start-AzureRmVM -ResourceGroupName $AzureResourceGroup -Name $_.Name;
}
};
}

10. After putting in values like AzureCredentials and SubscriptionID , test it in Test pane before publishing it.

11. Put in the values for the resource group and If you want to shut down or start the machine.

12. After our modifications are done, we need to publish the Runbook:

13. Now we need to schedule the Runbook:

At this point we are good to go with the schedule and Runbooks. Custom scripts can be tedious so I wanted to share another (simple) Runbook that will start and stop ARM VMs:

# Get AutomationPSCred Asset you use to do automation work
# This account behind the asset must be granted access to the ResourceGroup
$Cred = Get-AutomationPSCredential -Name "AzureCredentialname"
write-output $cred
# Specify Resource Group where ARM VMs were created
$vnetResourceGroup = "GroupName"
$AzureSubscriptionIDAssetName = 'SubscriptionID'
$SubID = Get-AutomationVariable -Name $AzureSubscriptionIDAssetName
Add-AzureRmAccount -Credential $Cred -SubscriptionId $SubID
#get the list of VMs in the resource group
$vmList = Get-AzureRmVM -ResourceGroupName $vnetResourceGroup
write-output $vmList
#To start the virtual machines
write-output "Starting VMs"
start-AzureRmVM -ResourceGroupName "GroupName" -Name "VMname"
#To stop the Virtual Machines
write-output "Stopping VMs"
stop-AzureRmVM -ResourceGroupName "GroupName" -Name "VMname"

I hope this post helps and provides enough information to setup Automation Accounts and schedule your Runbooks. Please let me know in the comments below if you have any feedback!

Rupanter Chhabra , Support Engineer
Microsoft Enterprise Cloud Group

%3CLINGO-SUB%20id%3D%22lingo-sub-351571%22%20slang%3D%22en-US%22%3EHow%20to%20Setup%20and%20Configure%20Microsoft%20Azure%20Automation%20Runbooks%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-351571%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Jun%2006%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3CEM%3E%20~%20Rupanter%20Chhabra%20%7C%20Microsoft%20Support%20Engineer%20%3C%2FEM%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3E%20%3CSTRONG%3E%20UPDATED%2006%2F13%2F2016%3A%20%3C%2FSTRONG%3E%20%3C%2FSTRONG%3E%20%3CEM%3E%20Azure%20Automation%20has%20a%20new%20way%20to%20connect%20with%20Azure%20ARM%20resources%20and%20soon%20will%20also%20support%20a%20new%20way%20to%20connect%20with%20Azure%20Classic%20resources.%26nbsp%3B%20See%20this%20article%20for%20more%20information%3A%20%3C%2FEM%3E%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fautomation-sec-configure-azure-runas-account%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20%3CEM%3E%20https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fautomation-sec-configure-azure-runas-account%2F%3C%2FEM%3E%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3E%20%3D%3D%3D%3D%3D%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%20%20%3CP%3EHi%20everyone%2C%20we%20get%20a%20lot%20of%20questions%20regarding%20Azure%20Automation%20so%20I%20thought%20I%E2%80%99d%20take%20a%20few%20minutes%20and%20walk%20through%20an%20example%20of%20how%20to%20get%20everything%20set%20up%2C%20how%20to%20import%20a%20Runbook%20and%20then%20schedule%20a%20published%20workflow.%20In%20this%20particular%20example%20I%E2%80%99ll%20demonstrate%20how%20to%20configure%20Azure%20Automation%20to%20start%2Fstop%20ARM%20virtual%20machines%2C%20however%20the%20general%20process%20can%20be%20used%20for%20a%20variety%20of%20tasks.%3C%2FP%3E%0A%20%20%3CP%3ETo%20get%20started%2C%20we%20first%20need%20to%20create%20an%20Azure%20Active%20Directory%20user%20that%20we%20can%20use%20for%20automation%3A%3C%2FP%3E%0A%20%20%3CP%3E1.%20Select%20%3CSTRONG%3E%20Active%20Directory%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83083iEE7DA83CC0277D09%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EThis%20will%20forward%20you%20to%20Classic%20portal.%3C%2FP%3E%0A%20%20%3CP%3E2.%20Click%20%3CSTRONG%3E%20ADD%20USER%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83084i72DD696772E39076%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E3.%20Add%20the%20appropriate%20account%20information%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83085iEDD8F7316F6544FD%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E4.%20Next%20we%20need%20to%20select%20a%20role%20so%20that%20we%E2%80%99ll%20have%20the%20proper%20rights%20to%20access%20the%20virtual%20machines%20and%20the%20subscription.%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3ENOTE%20%3C%2FSTRONG%3E%20Do%20not%20enable%20Multifactor%20Authentication.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83086i95477F4B7BEC5C37%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EGet%20your%20temporary%20password%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83087iF20D389A099BB3D0%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83088i97AEEA51A4DA1B45%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E5.%20Now%20we%20need%20to%20allow%20this%20Azure%20Active%20Directory%20user%20to%20manage%20the%20Azure%20subscription%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83089i3A3A56B4F985F856%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E6.%20We%20need%20to%20be%20sure%20that%20we%20change%20the%20temporary%20password%20so%20here%20are%20the%20steps%3A%3C%2FP%3E%0A%20%20%3CUL%3E%0A%20%20%20%3CLI%3Ea.%20Start%20Internet%20Explorer.%20If%20you%E2%80%99re%20currently%20logged%2C%20be%20sure%20you%20log%20out%20of%20your%20current%20Azure%20Account.%3C%2FLI%3E%0A%20%20%20%3CLI%3Eb.%20Log%20in%20to%20Azure%20by%20using%20the%20%3CSTRONG%3E%20.onmicrosoft.com%20%3C%2FSTRONG%3E%20account%20that%20we%20created%20earlier%20(the%20Active%20Directory%20User%20account).%3C%2FLI%3E%0A%20%20%20%3CLI%3Ec.%20You%20will%20now%20be%20prompted%20to%20change%20the%20user%E2%80%99s%20password.%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%20%3CP%3E7.%20Now%20we%20need%20to%20create%20the%20Azure%20Automation%20account.%20Start%20by%20selecting%20%3CSTRONG%3E%20Automation%20Accounts%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83090i4BE4EE9E79DB60F6%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EClick%20on%20%3CSTRONG%3E%20Add%20%3C%2FSTRONG%3E%20for%20a%20new%20Automation%20Account%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83091i591DCA6FD31B0A3F%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EAdd%20your%20Automation%20Account%20name%20and%20select%20Resource%20Group%20(New)%20to%20create%20a%20new%20one.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83092i8F9CD861F885815F%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83093iAF564DDBE771E275%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E8.%20Next%20we%20need%20to%20add%20%3CSTRONG%3E%20ASSETS%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83094iD07B53926A6E6B53%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EAdd%20the%20following%3A%3C%2FP%3E%0A%20%20%3CUL%3E%0A%20%20%20%3CLI%3EThe%20Automation%20credential%20asset%20called%20%3CB%3E%20AzureCredential%20%3C%2FB%3E%20that%20contains%20the%20Azure%20AD%20user%20credential%20(the%20%3CSTRONG%3E%20.onmicrosoft.com%20%3C%2FSTRONG%3E%20account%20that%20we%20created%20earlier).%3C%2FLI%3E%0A%20%20%20%3CLI%3EThe%20Automation%20variable%20asset%20called%20%3CB%3E%20AzureSubscriptionId%20%3C%2FB%3E%20that%20contains%20the%20Azure%20subscription.%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%20%3CP%3EFirst%20we%20add%20%3CSTRONG%3E%20Credential%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83095i58CC294F688CCD67%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83096i4FC60F94E13D4F5E%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EThen%20we%20need%20to%20add%20a%20%3CSTRONG%3E%20Variable%20%3C%2FSTRONG%3E%20which%20contain%20our%20Azure%20Subscription%20ID%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83097i0322F418C9108D14%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83098i8D47A4A797B45BB8%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3ENow%20we%20have%20all%20needed%20Assets.%3C%2FP%3E%0A%20%20%3CP%3E9.%20Next%20we%20need%20to%20select%20%3CSTRONG%3E%20Runbooks%20%3C%2FSTRONG%3E%20and%20import%20the%20needed%20Runbooks%20from%20the%20gallery%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83099i3107D087FCCEEE3E%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83100i94E30B2367B6DB08%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3ESelect%20Start%20Azure%20ARM%20VMs%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83101iB6A4416EC7B1702C%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EImport%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83102iFFA3E95B859B103A%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83103i15F671077715A6A5%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3ESelect%20%3CSTRONG%3E%20Edit%20%3C%2FSTRONG%3E%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83104i55062CA41C4D9BAA%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20script%20will%20look%20like%20this%20after%20removing%20the%20ASM%20code.%20This%20is%20the%20Runbook%20from%20the%20Gallery%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CEM%3E%20workflow%20Shutdown-Start-VMs-By-Resource-Group1%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Param%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true)%5D%20%3CBR%20%2F%3E%20%5BString%5D%20%3CBR%20%2F%3E%20%24AzureResourceGroup%2C%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true)%5D%20%3CBR%20%2F%3E%20%5BBoolean%5D%20%3CBR%20%2F%3E%20%24Shutdown%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%23The%20name%20of%20the%20Automation%20Credential%20Asset%20this%20runbook%20will%20use%20to%20authenticate%20to%20Azure.%20%3CBR%20%2F%3E%20%24CredentialAssetName%20%3D%20%22AzureCredential%22%3B%20%3CBR%20%2F%3E%20%23Get%20the%20credential%20with%20the%20above%20name%20from%20the%20Automation%20Asset%20store%20%3CBR%20%2F%3E%20%24Cred%20%3D%20Get-AutomationPSCredential%20-Name%20%24CredentialAssetName%20%3CBR%20%2F%3E%20if(!%24Cred)%20%7B%20%3CBR%20%2F%3E%20Throw%20%22Could%20not%20find%20an%20Automation%20Credential%20Asset%20named%20'%24%7BCredentialAssetName%7D'.%20Make%20sure%20you%20have%20created%20one%20in%20this%20Automation%20Account.%22%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%23Connect%20to%20your%20Azure%20Account%20%3CBR%20%2F%3E%20Add-AzureRmAccount%20-Credential%20%24Cred%20%3CBR%20%2F%3E%20%23%23Add-AzureAccount%20-Credential%20%24Cred%26nbsp%3B%20%23%23As%20we%20are%20doing%20it%20for%20ARM%20Virtual%20Machines.%20%3CBR%20%2F%3E%20if(%24Shutdown%20-eq%20%24true)%7B%20%3CBR%20%2F%3E%20Write-Output%20%22Stopping%20VMs%20in%20'%24(%24AzureResourceGroup)'%20resource%20group%22%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20else%7B%20%3CBR%20%2F%3E%20Write-Output%20%22Starting%20VMs%20in%20'%24(%24AzureResourceGroup)'%20resource%20group%22%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%23ARM%20VMs%20%3CBR%20%2F%3E%20Write-Output%20%22ARM%20VMs%3A%22%3B%20%3CBR%20%2F%3E%20Get-AzureRmVM%20-ResourceGroupName%20%24AzureResourceGroup%20%7C%20ForEach-Object%20%7B%20%3CBR%20%2F%3E%20if(%24Shutdown%20-eq%20%24true)%7B%20%3CBR%20%2F%3E%20Write-Output%20%22Stopping%20'%24(%24_.Name)'%20...%22%3B%20%3CBR%20%2F%3E%20Stop-AzureRmVM%20-ResourceGroupName%20%24AzureResourceGroup%20-Name%20%24_.Name%20-Force%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20else%7B%20%3CBR%20%2F%3E%20Write-Output%20%22Starting%20'%24(%24_.Name)'%20...%22%3B%20%3CBR%20%2F%3E%20Start-AzureRmVM%20-ResourceGroupName%20%24AzureResourceGroup%20-Name%20%24_.Name%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%3B%20%3CBR%20%2F%3E%20%7D%20%3C%2FEM%3E%3C%2FP%3E%0A%20%20%3CP%3E10.%20After%20putting%20in%20values%20like%20%3CSTRONG%3E%20AzureCredentials%20%3C%2FSTRONG%3E%20and%20%3CSTRONG%3E%20SubscriptionID%20%3C%2FSTRONG%3E%20%2C%20test%20it%20in%20%3CSTRONG%3E%20Test%20pane%20%3C%2FSTRONG%3E%20before%20publishing%20it.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83105iE7D66CA00B25DFE2%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E11.%20Put%20in%20the%20values%20for%20the%20resource%20group%20and%20If%20you%20want%20to%20shut%20down%20or%20start%20the%20machine.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83106iF3C4528E3164B3A6%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E12.%20After%20our%20modifications%20are%20done%2C%20we%20need%20to%20publish%20the%20Runbook%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83107i89B32CA3FB8310AA%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E13.%20Now%20we%20need%20to%20schedule%20the%20Runbook%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83108iB487AB1A9A905AB6%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83109i98B02FF8965191CF%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83110i63192ED0674686D5%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83111iCE011D5CBDAF7B10%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EAt%20this%20point%20we%20are%20good%20to%20go%20with%20the%20schedule%20and%20Runbooks.%20Custom%20scripts%20can%20be%20tedious%20so%20I%20wanted%20to%20share%20another%20(simple)%20Runbook%20that%20will%20start%20and%20stop%20ARM%20VMs%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CEM%3E%20%23%20Get%20AutomationPSCred%20Asset%20you%20use%20to%20do%20automation%20work%20%3CBR%20%2F%3E%20%23%20This%20account%20behind%20the%20asset%20must%20be%20granted%20access%20to%20the%20ResourceGroup%20%3CBR%20%2F%3E%20%24Cred%20%3D%20Get-AutomationPSCredential%20-Name%20%22AzureCredentialname%22%20%3CBR%20%2F%3E%20write-output%20%24cred%20%3CBR%20%2F%3E%20%23%20Specify%20Resource%20Group%20where%20ARM%20VMs%20were%20created%20%3CBR%20%2F%3E%20%24vnetResourceGroup%20%3D%20%22GroupName%22%20%3CBR%20%2F%3E%20%24AzureSubscriptionIDAssetName%20%3D%20'SubscriptionID'%20%3CBR%20%2F%3E%20%24SubID%20%3D%20Get-AutomationVariable%20-Name%20%24AzureSubscriptionIDAssetName%20%3CBR%20%2F%3E%20Add-AzureRmAccount%20-Credential%20%24Cred%20-SubscriptionId%20%24SubID%20%3CBR%20%2F%3E%20%23get%20the%20list%20of%20VMs%20in%20the%20resource%20group%20%3CBR%20%2F%3E%20%24vmList%20%3D%20Get-AzureRmVM%20-ResourceGroupName%20%24vnetResourceGroup%20%3CBR%20%2F%3E%20write-output%20%24vmList%20%3CBR%20%2F%3E%20%23To%20start%20the%20virtual%20machines%20%3CBR%20%2F%3E%20write-output%20%22Starting%20VMs%22%20%3CBR%20%2F%3E%20start-AzureRmVM%20-ResourceGroupName%20%22GroupName%22%20-Name%20%22VMname%22%20%3CBR%20%2F%3E%20%23To%20stop%20the%20Virtual%20Machines%20%3CBR%20%2F%3E%20write-output%20%22Stopping%20VMs%22%20%3CBR%20%2F%3E%20stop-AzureRmVM%20-ResourceGroupName%20%22GroupName%22%20-Name%20%22VMname%22%20%3C%2FEM%3E%3C%2FP%3E%0A%20%20%3CP%3EI%20hope%20this%20post%20helps%20and%20provides%20enough%20information%20to%20setup%20Automation%20Accounts%20and%20schedule%20your%20Runbooks.%20Please%20let%20me%20know%20in%20the%20comments%20below%20if%20you%20have%20any%20feedback!%3C%2FP%3E%0A%20%20%3CP%3E%3CSTRONG%3ERupanter%20Chhabra%20%3C%2FSTRONG%3E%20%2C%20Support%20Engineer%20%3CBR%20%2F%3E%20Microsoft%20Enterprise%20Cloud%20Group%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-351571%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Jun%2006%2C%202016%20~%20Rupanter%20Chhabra%20%7C%20Microsoft%20Support%20Engineer%20UPDATED%2006%2F13%2F2016%3A%20Azure%20Automation%20has%20a%20new%20way%20to%20connect%20with%20Azure%20ARM%20resources%20and%20soon%20will%20also%20support%20a%20new%20way%20to%20connect%20with%20Azure%20Classic%20resources.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-351571%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Orchestrator%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 11 2019 10:31 AM
Updated by: