Reconfigure/Edit SDRS Anti-Affinity Rules w/PowerCLi – Part 3

Cover

This is Part 3 of SDRS series.

In the previous part we learned how to create and remove anti-affinity rules. To close the topic, it remains to edit/reconfigure existing rules. Logical to assume, it will be Set-SdrsAntiAffinityRule function.

Set-SdrsAntiAffinityRule

  • The function allows to edit both Inter-VM and VMDK rules. Let’s go straight to examples.

Reconfigure Inter-VM Anti-Affinity Rules

  • Add two VM to an Inter-VM rule. We have to use -VM parameter. The default value for -Action parameter is Add, I explicitly used it here for more clarity.
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -VM (Get-VM vm1, vm2) -Action Add
  • Now let’s remove two another VM from the rule and at the same time rename and enable the rule!
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -VM (Get-VM vm1, vm2) -Action Remove -NewName Rule2 -Enable:$true

04.Set-SdrsAntiAffinityRule_RemoveVM

Reconfigure VMDK Anti-Affinity Rules

  • For VMDK rules we will use -HardDisk parameter. Let’s add one VM HardDisk. Please note, we did not use the -Action parameter. The default action is to add objects to rules.
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -HardDisk 3
  • Now we will remove it.
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -HardDisk 3 –Action Remove
  • The -HardDisk parameter can take more than one HardDisk Emoj.
Get-Help Set-SdrsAntiAffinityRule -Parameter HardDisk
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -HardDisk 2, 5, 7
  • If you omit the -HardDisk parameter, the function will add all VM Hard disks to the rule!
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule
  • This approach will not work for disks removal because API restrictions. Every VMDK rule must contain at least one HardDisk!

  • For mass disk removal from VMDK rules there is another approach. The simple PowerShell array operations.

Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -Action Remove -HardDisk (10..30)
  • Do you want to exclude some disks from a long array? No problem. The below example will take all disks from 10 to 30 and exclude two of them – 15 and 21.
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -Action Remove -HardDisk (10..30 –ne 15 –ne 21)
  • Do you want to exclude some disks from a long array and add several disks that is not from the range? It’s no problem too! The below example will take all disks from 10 to 30, exclude two disks – 15 and 21 and take two single disks – 32 and 45.
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Set-SdrsAntiAffinityRule -Action Remove -HardDisk (10..30 + 32 + 45 –ne 15 –ne 21)
  • Do not believe? Just run it in the PowerShell console.
(10..30 + 32 + 45 -ne 15 -ne 21)
(10..30 + 32 + 45 -ne 15 -ne 21) -join ', '

Summary

  • For more details about the function, please take a look at the content based help and examples.
Get-Command –Noun *sdrs*
Get-Help Set-SdrsAntiAffinityRule -Full
Get-Help Set-SdrsAntiAffinityRule -Examples

Anti-Affinity Rule restrictions

  • A VMDK rule must contain at least one HardDisk! It is senselessly to have single disk in a rule, but it is allowed.

  • A VM rule must contain at least two VM!

<< Part 2

You may also like:

Add PowerCLi version to the $PSVersionTable variable
Get-VMHostFirmwareVersion – Get ESXi servers BIOS/Firmware version
Set-VMHostNtpServer – Configure ESXi hosts NTP settings
Enable/Disable-VMHostSSH – Enable/Disable SSH on all ESXi hosts in a cluster

One thought on “Reconfigure/Edit SDRS Anti-Affinity Rules w/PowerCLi – Part 3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s