Installing Azure Site Recovery Agent (i.e. running an exe/script) on a Hyper-V host using SCVMM

From time to time I have the requirement to deploy/update a basic app or run a script on my Hyper-V hosts.

This is relatively simple using remote PS session or if you have SCCM managing your fleet. But sometimes you need to just push something out fast and luckily SCVMM can assist.

My use case is to run an update for the Microsoft Site Recovery Services Agent on my hosts. I would do this periodically.

All we need to have setup in SCVMM is to add the payload (install files) to a library location available to the target hosts.

In my case, I created a folder in my library called HostUpdates.cr and added the executable there

image

Next is to determine the commands I need to run

This is an update and I want to run it silently so my command line is MARSAgentInstaller.exe /q

To do this using the GUI, whilst selecting your target host, we need to use the “Run Script Command” function. (Either context menu or top ribbon)

image

For a basic deployment I set 3 parameters.

Executable program – In my case it’s the UNC path to the library item

Parameters – /q

Advanced > Restart Policy – disable restart the computer of virtual machine if the specified exit code is returned (I have never had a host reboot unexpectedly but this is just me being overly cautious)

Review the other settings and set accordingly for your deployment.

 image

 

image

 

Hit OK and your deployment should run..

image

 Well done, you’ve just very simply deployed your exe through SCVMM.

 

Ok, enough with the clicking already!!!

To do this to multiple hosts would take some time and an inordinate amount of clicking.

So, I use PowerShell to do this… For me, when the rare time I need to drop something on my hosts swiftly, I use my favourite old Our-Gridview for this.. You can use arrays or whatever input source that suits you.

An example of how I would do this below. As usual, this comes with no warranty whatsoever and remember that I expect you to be a grown adult and know what you’re doing 🙂

$scriptSetting = New-SCScriptCommandSetting
Set-SCScriptCommandSetting -ScriptCommandSetting $scriptSetting -WorkingDirectory "" `
    -PersistStandardOutputPath "" -PersistStandardErrorPath "" -MatchStandardOutput "" `
    -MatchStandardError ".+" -MatchExitCode "[1-9][0-9]*" -FailOnMatch `
    -RestartOnRetry $false -MatchRebootExitCode "" -RestartScriptOnExitCodeReboot $false `
    -AlwaysReboot $false

$VMHosts = Get-SCVMHost | select name | ogv -PassThru
ForEAch($VMHost in $VMHosts){
    $SCVMHost = Get-SCVMHost -ComputerName $VMhost.Name
    Invoke-SCScriptCommand -Executable "\\yourscvmmlibrary.domain.local\SCVMMLibrary\payload.cr\MARSAgentInstaller.exe" `
        -TimeoutSeconds 120 -CommandParameters "/q" -VMHost $SCVMHost `
        -ScriptCommandSetting $scriptSetting -RunAsynchronously
}

Hope this helps Smile

Cheers
Dan

Leave a Reply

Your email address will not be published. Required fields are marked *