So I thought it was about time to get stuck into Azure Automation. I am a fan of the product in theory, but have yet to delve into the details and figure it all out. Currently we run a number of on-premises powershell scripts on a number of servers performing various tasks. They get the job done, but in a decentralized way with limited visibility.
Having a product like Azure Automation storing, versioning, reporting, and of course, executing scripts would definitely add value, and it’s about time I get out of my old habits.
It’s not like me to start a blog straight into techie stuff, so here is my favourite joke…
I went to a Zoo and all they had was a dog.. it was a Shitzu
Ok that works better when spoken than written down… Now into it!
Setting up Azure Automation
- First up log on to your Azure Portal
- Click Add –> Monitoring + Management –> Automation
- Then set up an Automation Account. It needs some basic stuff, that is a name, subscription, resource group, and location.
- Click Create!
Create Operational Management Suite Workspace
If you don’t already have an Operational Management Suite account, create one as follows
- Complete the registration details to create an account
- Associate this with your Azure Active Directory
Deploy the Automation Solution in your OMS Workspace
- Log into your Operational Management Suite portal (Created above)
- Click Solutions –> Automation & Control to deploy the Automation Solution,
- Click Add to then deploy the solution.
- Alternatively, If a configure workspace button is only visible, click this first and associate it with your Resource Group and Automation Account created earlier. After which you can then Add the solution
Install Microsoft Monitoring Agent
- On an on premises machine you want to use as a Hybrid runbook worker, install the Microsoft Management Agent
- Login to your OMS Workspace https://yourworkspace.portal.mms.microsoft.com
- Click on Settings –>Connected Sources–>Windows Servers
- Download the appropriate Windows Agent.
- Kick off the install of the agent on your designated server.
- Ensure you check the box “Connect the agent to Azure Log Analytics (OMS)”
- Enter the Workspace ID and Workspace Primary Key specified in your OMS portal (see above screenshot).
- Complete the installation.
- Go to Control Panel –> Microsoft Monitoring Agent
- Click on the Azure Log Analytics (OMS) tab and verify connection is succesful
Create Hybrid Worker Group and connect agent to group
- Head back into your Azure portal
- Find your Automation Account created earlier (cloudy in my case)
- Click on the Keys Icon under essentials and take note of the Primary Access Key and URL
- Jump back on the server with the Monitoring Agent installed that you wish to use as your Hybrid Worker
- Start and Administrative Powershell Session and enter the following cmdlets to connect to Azure Automation
1234cd "C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\<version>\HybridRegistration"Import-Module .\HybridRegistration.psd1Add-HybridRunbookWorker –Url "URL" -Key "Primary Access Key" -GroupName "Cloudy_Servers"
- Use the URL and Primary Access Key from your Automation Account
- For Group Name, enter any name you wish. This is the Hybrid Worker Group that will exist in your Azure Portal. If the group doesn’t exist it will be created.
- You should now be able to see the new group in the Azure portal under your Azure Automation Account!
Create a Powershell Script already!!!
- Now we are good to go! Jump back in your Azure Portal
- on the Automation Account Click Runbooks –> Add a runbook –> Create a new runbook
- Call it RestartWorker with the type set to PowerShell
- Click Create
- Wait while it’s created, then once completed enter type the cmdlet:
- Click Save
- Click Test pane
- Select to run on a Hybrid Worker
- Select the Hybrid Worker group we created earlier
- Click Start
- All going to plan, your server has just restarted!
And that’s it!
I know… thats an awful amount of work to restart a computer 🙂 But now we have the base down to do some more advanced scripting shenanigans! I hope this is of use to someone.