Powercli script to get DRS rules

This is a simple little script to output some DRS rules to a txt which helps if you are running a green field migration of vCenter or for any reason need to reinstall your environment (rather you than me)


$outfile = "C:\rules.txt"
Remove-Item $outfile
$clusterName = "Cluster_Name"
$rules = "get-cluster -Name $clusterName | Get-DrsRule"</div>
<div>foreach($rule in $rules){
$line = (Get-View -Id $rule.ClusterId).Name
$line += ("," + $rule.Name + "," + $rule.Enabled + "," + $rule.KeepTogether)
foreach($vmId in $rule.VMIds){
$line += ("," + (Get-View -Id $vmId).Name)
$line | Out-File -Append $outfile

Leave a Comment

Your email address will not be published. Required fields are marked *