Hi,
How do I add a VM in a VMHostAffinity drs rule with powercli?
I tried with follows commands:
$vm = Get-VM M2-MVVIEW1
Set-DrsRule -Rule $affinityRule -VM $vm -Enabled $true;
but it didn't work, show a error message
Set-DrsRule : 16/11/2016 12:02:54 Set-DrsRule Unsupported rule type. Only VMAffinityRule and VMAntiAffinityRule types are
supported.
At line:1 char:1
+ Set-DrsRule -Rule $affinityRule -VM $vm -Enabled $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-DrsRule], InvalidArgument
+ FullyQualifiedErrorId : ViCore_ComputeResourceServiceImpl_SetDrsRule_UnsupportedRuleType,VMware.VimAutomation.ViCore.Cmdlets.Commands
.SetDrsRule
You're trying to change a VM to Host affinity rule, that is currently not supported by the DRSRule cmdlets in PowerCLI.
We, Matt and myself, wrote a module that will allow you to create and maintain all DRS rules.
See the DRSRule module.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How did you get the rule in the $affinityRule variable?
Is there only one object in that variable?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
follow:
$affinityRule | select *
VMIds : {VirtualMachine-vm-4025, VirtualMachine-vm-4027, VirtualMachine-vm-4057, VirtualMachine-vm-4068...}
AffineHostIds : {HostSystem-host-421, HostSystem-host-423, HostSystem-host-425, HostSystem-host-427...}
AntiAffineHostIds :
Key : 202
Uid : /VIServer=domain\user@vcdp7:443/Cluster=ClusterComputeResource-domain-c26/DrsVMHostAffinityRule=202/
Cluster : VDI_Cluster_01
ClusterId : ClusterComputeResource-domain-c26
ClusterUid : /VIServer=domain\user@vcdp7:443/Cluster=ClusterComputeResource-domain-c26/
Name : VMS_TO_HOSTS_MM2
Enabled : True
Mandatory : False
Type : VMHostAffinity
ExtensionData : VMware.Vim.ClusterVmHostRuleInfo
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
You're trying to change a VM to Host affinity rule, that is currently not supported by the DRSRule cmdlets in PowerCLI.
We, Matt and myself, wrote a module that will allow you to create and maintain all DRS rules.
See the DRSRule module.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
tks LucD,
But I can not run this module.
Show this message:
Get-ClusterObjFromClusterParam : The term 'Get-ClusterObjFromClusterParam' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\me\DRSRule\DRSRule-Latest\DRSRule.psm1:155 char:5
+ Get-ClusterObjFromClusterParam -Cluster $Cluster | ForEach-Object ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-ClusterObjFromClusterParam:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
That function is defined in the DRSRuleUtil module.
This is a nested module in the DRSRule module, as defined in the DRSRule.manifest.
I notice you loaded the DRSRule module in a user directory, is that directory listed in the $env:PSModulePath variable?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, it was very helpfull!
Tks again.