Using the following code to import a list of VMs via csv and set the flag to update tools on reboot. It keeps failing with the error below and looking for some help on fixing syntax. Requirement is only to update specific blocks of VMs with the tools flag and then disable after successful update.
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm = Import-Csv "C:\temp\scripts\tools.csv"
Get-VM $vm | ForEach { $_.ExtensionData.ReconfigVM_task($vmConfigSpec) }
Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command
again.
At C:\Temp\scripts\vmtools_setupgrade_flag.ps1:7 char:8
+ Get-VM $vm | ForEach { $_.ExtensionData.ReconfigVM_task($vmConfigSpec) }
+ ~~~
You need to use the columnname from the CSV.
If your CSV looks like this
Name
VM1
VM2
VM3
You should do
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm = Import-Csv "C:\temp\scripts\tools.csv"
Get-VM $vm.Name | ForEach { $_.ExtensionData.ReconfigVM_task($vmConfigSpec) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You need to use the columnname from the CSV.
If your CSV looks like this
Name
VM1
VM2
VM3
You should do
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm = Import-Csv "C:\temp\scripts\tools.csv"
Get-VM $vm.Name | ForEach { $_.ExtensionData.ReconfigVM_task($vmConfigSpec) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference