Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 232869

DRS-Backup Script

$
0
0

Hi all,

 

I have a script to backup all DRS-Rules in current vCenter and to import it into new vCenter for migration, but have few VMs to Host rules "Run VMs on Hosts" type. So I found that there is a way around to create such a Rule by creating VM groups and Host groups and then the rule. But I can't find how to get the already existing groups in old vCenter and import it in the new vCenter. This is what I am using for Import and export of VMAffinityType rules -

 

Export -

if(Test-Path -Path $outfile){
     Remove-Item $outfile
}
get-datacenter | %{
     $dcName = $_.Name
     $_ | Get-Cluster | %{
          $clusterName = $_.Name
          $rules = $_ | Get-DrsRule
          if($rules){
               foreach($rule in $rules){
                    $line = $dcName + "," + $clusterName
                    $line += ("," + $rule.Name + "," + $rule.Enabled + "," + $rule.KeepTogether)
                    foreach($vmId in $rule.VMIds){
                              $line += ("," + (Get-View -Id $vmId).Name)
                    }
               $line | Out-File -Append $outfile
               }
          }
     }
}

 

 

Import -

 

$rules = Get-Content $outfile

 

foreach($rule in $rules){

     $ruleArr = $rule.Split(",")

     if($ruleArr[3] -eq "True"){$rEnabled = $true} else {$rEnabled = $false}

     if($ruleArr[4] -eq "True"){$rTogether = $true} else {$rTogether = $false}

     Get-Datacenter $ruleArr[0] | Get-Cluster $ruleArr[1] | `

     New-DrsRule -Name $ruleArr[2] -Enabled $rEnabled -KeepTogether $rTogether -VM (Get-VM -Name ($ruleArr[5..($ruleArr.Count - 1)]))

}

 

 

These are LUCD's scripts !!

 

Can anyone suggest a good way to integrate what I am looking for into these??

 

Attaching some screens showing my current Rules

 

Thanks,


Viewing all articles
Browse latest Browse all 232869

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>