rmahir
Your script should work well.
For my windows environment. the original script (hosting the installer on Azure Storage Container ) worked.
The script below worked for my windows environment.
Param([object]$WebhookData)
$eventData = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
if ($eventData.subject -match 'microsoft.compute/virtualmachines') {
$vmName = $eventData.subject.Split('/')[8]
$vmResourceGroupName = $eventData.subject.Split('/')[4]
Connect-AzAccount -Identity
$storageAccountName = Get-AutomationVariable "StorageAccountName"
$resourceGroupName = Get-AutomationVariable "ResourceGroupName"
## load file to storage account and download file to windows system.
$ctx = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName).Context
$sasUri = New-AzStorageBlobSASToken -Blob '<application name.exe>' -Container "software" -Permission "r" -ExpiryTime (Get-Date).AddHours(72) -Context $ctx -FullUri
## Install Windows Sensor into the Windows Server
$scriptBlock = @'
$sasUri = "VALUE"
Invoke-WebRequest -Uri $sasUri -OutFile "$env:C:\<application name.exe>" -Verbose
Start-Process -Wait C:\<application name.exe>? -ArgumentList '/install','/quiet','/norestart','CID=*******************'
'@
$scriptBlock | Out-File $env:C:\script.ps1
(Get-Content $env:C:\script.ps1 -Raw) -replace "VALUE", $sasUri | Set-Content $env:C:\script.ps1 -Force
Invoke-AzVMRunCommand -ResourceGroupName $vmResourceGroupName -VMName $vmName -ScriptPath $env:C:\script.ps1 -CommandId 'RunPowerShellScript' -Verbose
}
else {
Write-Output "Event subject does not match microsoft.compute"
}
AnthonyWatherston I updated the script and make sure it pointing to the appropriate policy for Linux devices. without appropriate software installed.
Didn't work. So now I'm trying a modular run-book approach.
I'm not making much success on it.