Hi All,
I need to add VMs to affinity rules.
for first I was trying to get the rules for a cluster but not able to fetch all the rules.
$vkcpw = Get-Content E:\vkcpw.txt | ConvertTo-SecureString -Key (Get-Content E:\V-center_aes.key) $vcentercredential = New-Object System.Management.Automation.PsCredential("USER",$vkcpw) Connect-VIServer -server 192.1.8.1 -Credential $vcentercredential $DRSRules = Get-Cluster | where {$_.Name -eq "Standard"} | Get-DrsRule ForEach ($DRSRule in $DRSRules) { "" | Select-Object-Property @{N="Name";E={$DRSRule.Name}}, @{N="Cluster";E={$DRSRule.Cluster.Name}}, @{N="KeepTogether";E={$DRSRule.KeepTogether}}, @{N="VMs";E={((Get-View-Id $DRSRule.VMIds).Name)}} }
The above code is fetching only the rules type "Separate Virtual Machines".
Please let me know how to fetch the rules type "Run VMs on Hosts"
Have a look at the Type parameter of the Get-DrsRule cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is not the Type I mean, it is the parameter on the Get-DrsRule cmdlet.
Have a look at the online cmdlet reference I linked to, more specifically Example 4
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Thanks for the response, but the image which I mentioned in my previous reply, it does not shows the VMHostAffinity type. it is showing all rest of the rules.
Did you actually look at Example 4?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Yes. you are talking about Get-Cluster'MyCluster1'|Get-DrsRule-TypeVMHostAffinity right?
But I got the solution using below
Get-DrsVMHostRule -Cluster "Standard"
Can you help me with how to add a VM to a specific rule?