if I try to turn off a rule beginning with A_ (for automated) with
$rules = Get-Cluster -Name $cluster | Get-DrsRule -Name "A_*"
foreach($rule in $rules) {
Set-DrsRule -Rule $rule -Enabled:$false -Confirm:$false
}
I get the error
Set-DrsRule : 01.02.2011 10:04:29 Set-DrsRule Not initialized: vim.VirtualMachine[] vm
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\DPM_test.ps1:91 char:22
+ Set-DrsRule <<<< -Rule $rule -Enabled:$false -Confirm:$false
+ CategoryInfo : NotSpecified: (:) [Set-DrsRule], InvalidRequest
+ FullyQualifiedErrorId : Client20_MoServiceImpl_Invoke_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetDrsRule
But this type of rule has no direct affinity to a vm? Who can help?
Best Regards
This should do the trick
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
$rules = Get-DrsRule -Name "A_*" -Cluster $cluster
if($rules){ $spec =New-Object VMware.Vim.ClusterConfigSpec
foreach($rule in $rules) { $RulesSpec = New-Object VMware.Vim.ClusterRuleSpec
$RulesSpec.Info = $rule.ExtensionData $RulesSpec.Info.Enabled = $false
$RulesSpec.Operation = "edit"
$spec.rulesSpec += $RulesSpec
} $cluster.ExtensionData.ReconfigureCluster($spec,$true) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you try running this in 32-bit mode ?
See Issue in New-OSCustomizationSpec in Power CLI 4.1.1 on how to do this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try this:
foreach ($rule in $rules)
{foreach ($vmid in $rule.VMIDs)
{$vm = get-vm -ID $vmid
Set-DrsRule -Rule $rule -vm $vm -Enabled:$false -Confirm:$false }
}
Please note - NO VC close - so untested (but I think it should work)
I have installed V4.1.0.2519 and start the powershell_ise.exe from c:\Windows\System32\WindowsPowerShell\v1.0 on W2k8r2. Should be 32-bit-mode.
Best Regards
I think you need to start like this for 32-bit.
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In my rules "Run VMs on Hosts" the VMIDs are empty.
Best regards
Hi LucD,
yes of course. The result is the same.
Best regards
Let's have a look at your rules.
Can you do ?
Get-Cluster -Name $cluster | Get-DrsRule -Name "A_*" | Select *
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Name : A_wsch0027
Enabled : True
ClusterId : ClusterComputeResource-domain-c10873
Cluster : yyyy
ClusterUid : /VIServer=@sxxxxxxx:443/Cluster=ClusterComputeResource-domain-c10873/
KeepTogether : False
VMIds : {}
Uid : /VIServer=@sxxxxxxx:443/Cluster=ClusterComputeResource-domain-c10873/DrsVMAffinityRule=6/
ExtensionData : VMware.Vim.ClusterVmHostRuleInfo
Name : A_wsch0028
Enabled : True
ClusterId : ClusterComputeResource-domain-c10873
Cluster : yyyy
ClusterUid : /VIServer=@sxxxxxxx:443/Cluster=ClusterComputeResource-domain-c10873/
KeepTogether : False
VMIds : {}
Uid : /VIServer=@sxxxxxxx:443/Cluster=ClusterComputeResource-domain-c10873/DrsVMAffinityRule=7/
ExtensionData : VMware.Vim.ClusterVmHostRuleInfo
Best regards
It looks as if you are using ESX(i) pre-4.1
I tested against ESX 4.1 where it works without a problem.
It could be a problem with the specific ESX version.
Perhaps someone from the Development Team can have a look ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
using VSphere Server 4.1.0 Build 258902, the last official version?!?
Best regards
Then it must be the PowerCLI version we are using.
Look at the type of the Extensiondata
Name : Some servers
Enabled : True
ClusterId : ClusterComputeResource-domain-c5
Cluster : MyCluster
ClusterUid : /VIServer=@xxxxxxx:443/Cluster=ClusterComputeResource-domain-c5/
KeepTogether : False
VMIds : {VirtualMachine-vm-33540, VirtualMachine-vm-18923, VirtualMachine-vm-36303}
Uid : /VIServer=@xxxxxxxx:443/Cluster=ClusterComputeResource-domain-c5/DrsVMAffinityRule=70/
ExtensionData : VMware.Vim.ClusterAntiAffinityRuleSpec
I'm using
PS C:\> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
VMware vCenter Update Manager PowerCLI 4.1 build 266648
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
old version
PowerCLIVersion
---------------
VMware vSphere PowerCLI 4.1 build 264274
new version
PowerCLI Version
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
error:
Set-DrsRule : 01.02.2011 11:59:36 Set-DrsRule Not initialized: vim.VirtualMachine[] vm
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\DPM_test.ps1:97 char:22
+ Set-DrsRule <<<< -Rule $rule -Enabled:$false -Confirm:$false
+ CategoryInfo : NotSpecified: (:) [Set-DrsRule], InvalidRequest
+ FullyQualifiedErrorId : Client20_MoServiceImpl_Invoke_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetDrsRule
Same with the newer version.
Best regards
Hi LucD,
your example show a "Run VMs on Hosts"-Rule? I my case the VMID's field are empty. That's is the problem maybe. I have create a DRS-VM-group an a DRS-hostgroup put it tigether with "Run VMs on Hosts".
Best regards
I created a test rule based on groups and now I see the same error you are seeing.
It seems you discovered a bug with rules that use DRS groups.
Let me see if I can find a bypass.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This should do the trick
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
$rules = Get-DrsRule -Name "A_*" -Cluster $cluster
if($rules){ $spec =New-Object VMware.Vim.ClusterConfigSpec
foreach($rule in $rules) { $RulesSpec = New-Object VMware.Vim.ClusterRuleSpec
$RulesSpec.Info = $rule.ExtensionData $RulesSpec.Info.Enabled = $false
$RulesSpec.Operation = "edit"
$spec.rulesSpec += $RulesSpec
} $cluster.ExtensionData.ReconfigureCluster($spec,$true) }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I can confirm that Drs rules "Run VMs on Hosts" are not supported in PowerCLI 4.1.1. I've already file a bug for this issue.
Thanks for the feedback.
Regards,
Yasen
PowerCLI Dev Team
P.S I think Luc's workaround should work also.
Thank you LucD, it works.