The DRSRule module allows you to work with all types of vSphere DRS rules. The module provides support for VM and VMHost groups. And, it works with affinity/anti-affinity VM rules and VM to VMHost rules.
The module came from the need for DRS rule/group info gathering, exporting, and recreating. Initially there were some code blocks for exporting rule info and for importing again those rules, but things evolved into a module.
A couple of examples:
Export-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json
Import-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json
Via the PowerShell Gallery and PowerShellGet:
Find-Module DRSRule | Save-Module -Path c:\temp\someFolder
Find-Module DRSRule | Install-Module
Or, the "old", manual way:
Unblock-File
on the extracted contentsImport-Module <path\To\ModuleFolder>
Get-Help
as per usual for cmdlet help and examplesExport-DrsRule
Import-DrsRule
Get-DrsVMGroup
Get-DrsVMHostGroup
Get-DrsVMToVMHostRule
Get-DrsVMToVMRule
New-DrsVMGroup
New-DrsVMHostGroup
New-DrsVMToVMHostRule
New-DrsVMToVMRule
Remove-DrsVMGroup
Remove-DrsVMHostGroup
Remove-DrsVMToVMHostRule
Remove-DrsVMToVMRule
Set-DrsVMGroup
Set-DrsVMHostGroup
Set-DrsVMToVMHostRule
Set-DrsVMToVMRule