Skip to content

Instantly share code, notes, and snippets.

@thereverand
Last active April 17, 2017 00:32
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 thereverand/90924c649146af69a3ad3f150b80931f to your computer and use it in GitHub Desktop.
Save thereverand/90924c649146af69a3ad3f150b80931f to your computer and use it in GitHub Desktop.
Configures a machine monitored with the Microsoft Monitoring Agent as a Hybrid Worker for use with Azure Automation; without needing to know the version the agent you are running.
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[string]$Url,
[parameter(Mandatory=$true)]
[string]$Key,
[parameter(Mandatory=$true)]
[string]$GroupName
)
# The path to the latest version of the MMAgent
# Get all the folders for installed versions
# Sort them by Name, cast to a Version, from newest to oldest
# And Select the latest (first) one.
$latestPath =
Get-ChildItem -Path "C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\" `
| Sort-Object { [Version]$_.Name } -Descending `
| Select-Object -First 1;
# Import the Hybrid Registration module
Import-Module "$latestPath\HybridRegistration\HybridRegistration.psd1";
# Enable this machine as a Hybrid Worker for Azure Automation with the supplied parameters.
Add-HybridRunbookWorker –Url $Url -Key $Key -GroupName $GroupName;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment