Need a script to import DRS rules and export DRS rules...
the output in .csv format
See Arne's post called PowerCLI: Export, Import and Create DRS Rules v2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
before posting in communities i checked it.
Export of DRS rules works fine..
The same tried to import it, but it did not work.
Is the export/import done on the same vCenter ?
It also looks as if the cluster doesn't exist where you are doing the import.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Now i export/imported the DRS rules , same vcenter,same cluster.. Still get error.
Get-VM : Cannot validate argument on parameter 'Id'. The argument is null, empt
y, or an element of the argument collection contains a null value. Supply a col
lection that does not contain any null values and then try the command again.
At C:\users\xxxxx\desktop\scripts\DRS Rules\import drs rules.ps1:6 char:20
+ -VM (Get-VM -Id <<<< $rule.VmIds)}
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValid
ationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
ation.ViCore.Cmdlets.Commands.GetVM
===========
To import i am using the below script.
# Import DRS ForEach ($rule in (Import-CliXml 'C:\scripts\drs.xml')){ New-DrsRule -Cluster (Get-Cluster -Name "Cluster_01") ` -Name $rule.Name -Enabled $rule.Enabled ` -KeepTogether $rule.KeepTogether ` -VM (Get-VM -Id $rule.VmIds)}
That seems to work for me.
Did you check the contents of the XML file and verified if those IDs are for existing VMs on the cluster ?
There appear to be some issues with New-DrsRule cmdlet when you try to add rules to a cluster that has already rules (created in vSphere 4.x).
I got the following error in such a situation.
New-DrsRule : 27-03-2012 18:20:29 New-DrsRule Unable to cast object of type 'VMware.Vim.ClusterVmHostRuleInfo'
to type 'VMware.Vim.ClusterAntiAffinityRuleSpec'.
At line:1 char:12
+ New-DrsRule <<<< -Cluster MyCluster -name test -enabled $true -vm (Get-VM VM1,VM2) -KeepTogether $false
+ CategoryInfo : NotSpecified: (:) [New-DrsRule], ViError
+ FullyQualifiedErrorId : Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cmdl
ets.Commands.NewDrsRule
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I will verify the VM id from xml file..