A few days ago, I needed to on-board Azure Windows Server VMs with Microsoft Windows Defender Advanced Threat Protection, or in short, MDATP. Sometimes Azure Security Center (ASC) has issues with on-boarding VMs and deploying the MDATP agent. As a result, I wrote the following PowerShell script that will download the MDATP.cmd file from my Azure Blob container and install it locally to the VM. This script allows you to automate it for many VMs to the scope of a Resource Group.
Now there are a few assumptions here…
- Download the MDATP.cmd file from the Defender Security Center portal
- Remove the requirement for user consent for the MDATP execution
- Upload the modified MDATP file to an Azure Blob container
- Generated a SAS URI for the MDATP file
There are many examples on the Internet on how to go step #4. Maybe in time I will do another post.
To remove the requirement of the MDATP agent to execute based on user interaction/consent can be done by removing, or commenting out the following lines of code. Launch the MDATP.cmd file within Notepad, and add a “:” before each line of code from lines 9 through 19, except line 14. Should look something like this.
Now, update and run the following PowerShell code. You can validate the VM is calling back to the Defender Security Center portal or by running the MDATPClientAnalyzer on the VM.
#update resource as needed $resourcegroup = "YOUR_RESOURCE_GROUP" #get only Windows Server VMs $vms = Get-AzVM -ResourceGroupName $resourcegroup | Where-Object {$_.StorageProfile.OSDisk.OSType -eq "Windows"} | Select-Object Name foreach ($vm in $vms) { #friendly start message to indicate which server has started Write-Host "Server $vm has started..." #create folder, do not display error if folder already exists New-Item -Path "C:\" -Name "MDATP" -ItemType "directory" -ErrorAction SilentlyContinue #download MDATP.cmd file from Storage Account with SAS URI. Execute the cmd file. Passing "Y" to continue with installation. Invoke-WebRequest -Uri "YOUR_URI_SAS" -OutFile WindowsDefenderATPLocalOnboardingScript.cmd; Start-Process -FilePath "C:\MDATP\WindowsDefenderATPLocalOnboardingScript.cmd" -Verb RunAs #sleep for 5 seconds Start-Sleep -Seconds 5 #restart-server Restart-Computer -ComputerName $vm #friendly finished message to indicate which server has completed and will now reboot Write-Host "Server $vm has completed, reboot initiated..." }