Sunday, June 13, 2021

Powershell script to disable/ enable vmwaretool with report status.

Powershell script to disable/ enable vmwaretool with report status.

#####################To Disable ###########################
$ErrorActionPreference='silentlycontinue'
Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}
$vmt=Get-VM|Get-View | select name,@{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } } |Sort Name
$results +=$vmt
$results | Export-Csv C:\ry\ansible\vmtoolstatus.csv

##########################To Enable####################################

$ErrorActionPreference='silentlycontinue'
Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}
$vmt=Get-VM|Get-View | select name,@{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } } |Sort Name
$results +=$vmt
$results | Export-Csv C:\ry\ansible\vmtoolstatus.csv

No comments: