6 Replies Latest reply on Mar 27, 2012 10:02 AM by nareshunik

    Import and export DRS rules

    nareshunik Hot Shot

      Need a script to import DRS rules and export DRS rules...

       

      the output in .csv format

        • 1. Re: Import and export DRS rules
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Import and export DRS rules
            nareshunik Hot Shot

            before posting in communities i checked it.

             

            Export of DRS rules works fine..

             

            The same tried to import it, but it did not work.

             

             

            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\cz3m7g\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
            Get-Cluster : 3/25/2012 11:17:59 AM    Get-Cluster        Cluster with name 'CP
            THI05' was not found, using the specified filter(s).
            At C:\users\cz3m7g\desktop\scripts\DRS Rules\import drs rules.ps1:3 char:38
            +     New-DrsRule -Cluster (Get-Cluster <<<<  -Name "CPTHI05") `
                + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
               utomation.ViCore.Cmdlets.Commands.GetCluster
            Get-VM : 3/25/2012 11:18:01 AM    Get-VM        VM with id 'VirtualMachine-vm-1
            290' was not found, using the specified filter(s).
            At C:\users\cz3m7g\desktop\scripts\DRS Rules\import drs rules.ps1:6 char:16
            +     -VM (Get-VM <<<<  -Id $rule.VmIds)}
                + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException
                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
               utomation.ViCore.Cmdlets.Commands.GetVM
            Get-VM : 3/25/2012 11:18:01 AM    Get-VM        VM with id 'VirtualMachine-vm-1
            291' was not found, using the specified filter(s).
            At C:\users\cz3m7g\desktop\scripts\DRS Rules\import drs rules.ps1:6 char:16
            +     -VM (Get-VM <<<<  -Id $rule.VmIds)}
                + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException
                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
               utomation.ViCore.Cmdlets.Commands.GetVM
            New-DrsRule : Cannot bind parameter 'Cluster'. Cannot convert the "" value of t
            ype "System.Management.Automation.PSCustomObject" to type "VMware.VimAutomation
            .ViCore.Types.V1.Inventory.Cluster".
            At C:\users\cz3m7g\desktop\scripts\DRS Rules\import drs rules.ps1:3 char:25
            +     New-DrsRule -Cluster <<<<  (Get-Cluster -Name "CPTHI05") `
                + CategoryInfo          : InvalidArgument: (:) [New-DrsRule], ParameterBin
               dingException
                + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat
               ion.ViCore.Cmdlets.Commands.NewDrsRule
            Get-Cluster : 3/25/2012 11:18:01 AM    Get-Cluster        Cluster with name 'CP
            THI05' was not found, using the specified filter(s).
            At C:\users\cz3m7g\desktop\scripts\DRS Rules\import drs rules.ps1:3 char:38
            +     New-DrsRule -Cluster (Get-Cluster <<<<  -Name "CPTHI05") `
                + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
               utomation.ViCore.Cmdlets.Commands.GetCluster
            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\cz3m7g\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
            • 3. Re: Import and export DRS rules
              LucD Guru
              Community WarriorsvExpertUser Moderators

              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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Import and export DRS rules
                nareshunik Hot Shot

                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)}
                • 5. Re: Import and export DRS rules
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Import and export DRS rules
                    nareshunik Hot Shot

                    I will verify the VM id from xml file..