vmware-oebb
Contributor
Contributor

Get VM DRS-Group and Datatsore

Jump to solution

Hello,

I'm a Script Newbie.

Hope somebody can help me. This Script works fine. But I Need also the Datastore Location of each VM.

$Cluster = Get-Cluster -Name <Name>

$vmsInGroup = $cluster.ExtensionData.ConfigurationEx.Group | where {$_-is [VMware.Vim.ClusterVmGroup]} | %{Get-View -Id $_.VM | Select -ExpandProperty Name}

$VMsNotInDrsGroup = @(Get-VM -Location $Cluster | where {$vmsInGroup -notcontains $_.Name} | Select Name,VMHost | Sort VMHost)

Thank you

Andi

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try like this

$Cluster = Get-Cluster -Name <Name>

$vmsInGroup = $cluster.ExtensionData.ConfigurationEx.Group | where {$_ -is [VMware.Vim.ClusterVmGroup]} | %{Get-View -Id $_.VM | Select -ExpandProperty Name}

$VMsNotInDrsGroup = @(Get-VM -Location $Cluster |

                      where {$vmsInGroup -notcontains $_.Name} |

                      Select Name,VMHost,@{N='Datastore';E={$_.ExtensionData.Config.Files.vmPathName.Split(']')[0].TrimStart('[')}} | Sort VMHost)


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

Try like this

$Cluster = Get-Cluster -Name <Name>

$vmsInGroup = $cluster.ExtensionData.ConfigurationEx.Group | where {$_ -is [VMware.Vim.ClusterVmGroup]} | %{Get-View -Id $_.VM | Select -ExpandProperty Name}

$VMsNotInDrsGroup = @(Get-VM -Location $Cluster |

                      where {$vmsInGroup -notcontains $_.Name} |

                      Select Name,VMHost,@{N='Datastore';E={$_.ExtensionData.Config.Files.vmPathName.Split(']')[0].TrimStart('[')}} | Sort VMHost)


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

0 Kudos
vmware-oebb
Contributor
Contributor

Hi Luc,

Script works fineSmiley Happy. Thank you so much.

Andi

0 Kudos