Hi, I am new to powershell and got the below script (from http://damiankarlson.com/2011/01/13/managing-vmware-has-vm-monitoring-powercli/ thanks Damian Karlson) that will allow me to set the "VM Monitoring" setting for each VM in a cluster to "Disabled" status. This is necessary to enable "VM and Application Monitoring" at top level and keep only selective VMs enabled for monitoring. When I run this script, it gets applied VM1. When i try to apply this for another VM with a change in VM name (to VM2), it get "Specified parameter was not correct” error in vCenter tasks. Not sure whats wrong, any help is appreciated.
$srv = Connect-VIServer vcenter01
$vm = Get-VM -Name VM1
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.dasVmConfigSpec = New-Object VMware.Vim.ClusterDasVmConfigSpec[] (1)
$spec.dasVmConfigSpec[0] = New-Object VMware.Vim.ClusterDasVmConfigSpec
$spec.dasVmConfigSpec[0].operation = "edit"
$spec.dasVmConfigSpec[0].info = New-Object VMware.Vim.ClusterDasVmConfigInfo
$spec.dasVmConfigSpec[0].info.key = New-Object VMware.Vim.ManagedObjectReference
$spec.dasVmConfigSpec[0].info.key.type = "VirtualMachine"
$spec.dasVmConfigSpec[0].info.key.value = $vm.ExtensionData.MoRef.Value
$spec.dasVmConfigSpec[0].info.dasSettings = New-Object VMware.Vim.ClusterDasVmSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.enabled = $false
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringDisabled"
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings.clusterSettings = $false
$_this = Get-View -Id $vm.VMHost.Parent.Id