VMware Cloud Community
andrevechiatto
Enthusiast
Enthusiast
Jump to solution

DRS RULES LIST VMS

Hi people,

Please

Is possible to list all vms that are not part of drs rule group with Powercli?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$clusterName = 'MyCluster'

$cluster = Get-view -ViewType ClusterComputeResource -Property Host,ConfigurationEx -Filter @{'Name'=$clustername}

$VmInGroup = $cluster.ConfigurationEx.Group | %{$_.VM | %{$_.Value}}

Get-View -Id $cluster.Host -Property VM | %{

    if($_.VM){

        Get-View -Id $_.VM -Property Name | where{$VmInGroup -notcontains $_.MoRef.Value} | select Name

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$clusterName = 'MyCluster'

$cluster = Get-view -ViewType ClusterComputeResource -Property Host,ConfigurationEx -Filter @{'Name'=$clustername}

$VmInGroup = $cluster.ConfigurationEx.Group | %{$_.VM | %{$_.Value}}

Get-View -Id $cluster.Host -Property VM | %{

    if($_.VM){

        Get-View -Id $_.VM -Property Name | where{$VmInGroup -notcontains $_.MoRef.Value} | select Name

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

andrevechiatto
Enthusiast
Enthusiast
Jump to solution

Luc,

Thanks your help.

Is possible to list all clusters in the virtual center?

Reply
0 Kudos
ScottDriver42
Enthusiast
Enthusiast
Jump to solution

$(get-cluster).name

You could just pump it into a foreach with Luc's script above.

Blog: https://virtualvt.wordpress.com/ | Twitter: VTsnowboarder42
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Or leave out the Filter

Get-view -ViewType ClusterComputeResource -Property Host,ConfigurationEx | %{

    $VmInGroup = $_.ConfigurationEx.Group | %{$_.VM | %{$_.Value}}

    Get-View -Id $_.Host -Property VM | %{

        if($_.VM){

            Get-View -Id $_.VM -Property Name | where{$VmInGroup -notcontains $_.MoRef.Value} | select Name

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
andrevechiatto
Enthusiast
Enthusiast
Jump to solution

Thanks Luc

The error below appeared

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or

empty. Provide an argument that is not null or empty, and then try the command

again.

+     Get-View -Id $cluster.Host -Property VM | %{

+                  ~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingVal

   idationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

   ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, my bad.

The code above is corrected


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos