Hi @Vedran Banjeglav ,
This script uninstalls a specific Windows update (KB4589208) from a list of virtual machines (VMs) .It iterates through each VM, retrieves its resource group and name, and uses the Invoke-AzVMRunCommand
to run a PowerShell command to uninstall the update. If the command fails, it catches and logs the error.
$vms= @( "vm1", "vm02")
$KB= "4589208"
foreach ($vm in $vms) {
$Temp= get-azvm|?{$_.Name -eq $vm}
$resourceGroupName = $Temp.ResourceGroupName
$vmName = $Temp.Name
Write-Output "Uninstalling update on VM: $vmName in Resource Group: $resourceGroupName"
try {
Invoke-AzVMRunCommand -ResourceGroupName $resourceGroupName -VMName $vmName -CommandId 'RunPowerShellScript' -ScriptString "wusa /uninstall /kb:$KB /quiet /norestart"
Write-Output "Update uninstall command sent to VM: $vmName"
} catch {
Write-Output "Failed to send command to VM: $vmName. Error: $_"
}
}
Let me know if you need further clarification or assistance!
Feel free to reach out if you have any further questions or need additional information—I’m happy to assist!
Please provide your valuable comments
Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.