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
## Install sensor into the Linux Server
$scriptBlock = @'
sudo apt-get install git
sudo wget https://application pull location
sudo dpkg -i application.deb
sudo chmod 777
sudo /opt/aplicationfolder/application -s --cid=xxxxxxxxxxxxxxxxxxxx-xx
sudo service application-name start
'@
$scriptBlock | Out-File $env:TEMP\script.sh
Invoke-AzVMRunCommand -ResourceGroupName $vmResourceGroupName -VMName $vmName -ScriptPath $env:TEMP\script.sh -CommandId 'RunShellScript' -Verbose
}
else {
Write-Output "Event subject does not match microsoft.compute"
}
LeonardEsere - I think the script should look something more like this :). check the policy assigned - for linux it should be "
My deployment templates only handle the windows example - Linux has a different policy