I appreciate this sort of question has been asked before but in my trials i cannot find how to achieve what i want. I also appreciate i'm a little out of my depth as I've not ever played around with the powercli module and this is my first attempt
I want to change the policy of any VM that is currently set to "upgradeatpowercycle", to "manual". I'd prefer not to just do a blank across the hosts but rather a cluster (or specific machines) at a time, so through looking through documentation/forums/ trial and error etc I thought i had it with this:
$cluster = get-cluster 'CL-DEV-NP'
$servers = $cluster | Get-VM
#param([string]$servers)
$spec= new-object vmware.vim.virtualmachineconfigspec
$spec.tools=new-object vmware.vim.toolsconfiginfo
$spec.tools.toolsupgradepolicy ="manual"
$vms= get-vm $servers
Foreach($vm in $vms){
$view=$vm | get-view -ViewType virtualmachine -SearchRoot $cluster.Id -Filter @{'Config.Tools.ToolsUpgradePolicy' = 'upgradeAtPowerCycle' }
$view.reconfigvm($spec)
}
this produces this error:
get-view : The input object cannot be bound to any parameters for the command either
because the command does not take pipeline input or the input and its properties do
not match any of the parameters that take pipeline input.
At line:56 char:11
+ $view=$vm|get-view -ViewType virtualmachine -SearchRoot $cluster.Id ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (ueb-dev-01:PSObject) [Get-View], Para
meterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets
.Commands.DotNetInterop.GetVIView
I'm guessing I need to do the filtering beforehand and make it in a format that will be accepted but i cannot seem to get the result of :
get-view -ViewType virtualmachine -SearchRoot $cluster.Id -Filter @{'Config.Tools.ToolsUpgradePolicy' = 'upgradeAtPowerCycle' }
into a format i can use.
I've seen ways to do it by feeding the vm's into the script from txt files but i'd rather do it via a search first. Could somebody help point me in the right direction to achieving what i'm trying to do
Kind Regards