VMware Cloud Community
nlong12
Enthusiast
Enthusiast
Jump to solution

Report on a vm VMhost Group not working

Good morning;

Attempting to list the VMHost Group associated with our sql server vm's.  Here is what I'm seeing:

First the simple minded powershell script

$vm = Foreach ($vm in get-vm -Name "fwsql*" | where { ($_.PowerState -eq "PoweredOn")}) {

Get-DrsClusterGroup -VM $vm  | Select-Object Name, Member | sort Name -Descending} 

And the results

Name Member

---- ------

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

NonSQL Servers    {Xxapp224, Xxapp196, Xxapp198, XXAPP246...}

NonSQL Servers    {Xxapp224, Xxapp196, Xxapp198, XXAPP246...}

NonSQL Servers    {Xxapp224, Xxapp196, Xxapp198, XXAPP246...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

NonSQL Servers    {Xxapp224, Xxapp196, Xxapp198, XXAPP246...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

PROD SQL SERVERS  {XXSQL249, XXSQL245, XXSQL246, Xxapp292...}

Why this is occurring is beyond my me, any and all advice would be appreciated

Norm 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Because that is the way PowerShell shows an array on screen.
Try like this (which converts the array to single string of the concatenated names).

$VMs = Get-VM | Where {$_.name -like "fwsql*" -and $_.PowerState -eq "PoweredOn"}

Get-DrsClusterGroup -VM $VMs | Select Name, @{N = 'Member'; E = {$_.Member.Name -join '|'}} |

   Sort-Object -Property Name -Descending


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Your ForEach variable ($vm) is the same as the variable to which you assign the result ($vm)


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

Reply
0 Kudos
nlong12
Enthusiast
Enthusiast
Jump to solution

Hello Lucd;

Thank you for pointing out my error.  However still getting the same output.  Here is my revised code:

$VMs = Get-VM | Where {($_.name -like "fwsql*")} | where {$_.PowerState -eq "PoweredOn"} | Select-Object Name | sort

$Output=Foreach ($VM in $VMs){

    Get-DrsClusterGroup -VM $VM.Name | Select-Object Name, Member | sort Name -Descending

    }

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

First, I assume you were running something like this.

Because in the previous script you select the Name (a string) of the VMs, and then look for the property Name (with $vm.Name), which doesn't exist.

You can fix that by doing

$VMs = Get-VM | Where  {$_.name -like "fwsql*" -and $_.PowerState -eq "PoweredOn"} | Sort-Object -Property Name

$Output=Foreach ($VM in $VMs){

   Get-DrsClusterGroup -VM $VM.Name | Select-Object Name, Member | sort Name -Descending

}

For each VM you retrieve the group to which it belongs.

But the same group can come back multiple times, due to the fact that a group can contain multiple VMs.
You could do

$VMs = Get-VM | Where {$_.name -like "fwsql*" -and $_.PowerState -eq "PoweredOn"}

Get-DrsClusterGroup -VM $VMs | Select Name, Member |

   Sort-Object -Property Name -Descending


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

Reply
0 Kudos
nlong12
Enthusiast
Enthusiast
Jump to solution

Hello Lucd,

Ran with your suggestion and still not getting the desired output.  Maybe I'm approaching incorrectly.  Here is the output

Name              Member                                    

----              ------                                    

PROD SQL SERVERS  {FWSQL999, FWSQL999, FWSQL999, FWXXX999...}  ---> There are more than three vm's in host group - display is not complete

NonSQL Servers    {FWXXX999, FWXXX999, FWXXX999, FWXXX999...}  ----> There are more than three vm's in host group - display is not complete

LARGE SQL Servers {FWSQLXXX999, FWSQLXXX999, FWSQL999}       ---> only three here so display is okay.

So the question is why I'm not able to see all of the vm's in the first two hostgroups?

Thank you for your help!!!!

Norm

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Because that is the way PowerShell shows an array on screen.
Try like this (which converts the array to single string of the concatenated names).

$VMs = Get-VM | Where {$_.name -like "fwsql*" -and $_.PowerState -eq "PoweredOn"}

Get-DrsClusterGroup -VM $VMs | Select Name, @{N = 'Member'; E = {$_.Member.Name -join '|'}} |

   Sort-Object -Property Name -Descending


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

Reply
0 Kudos
nlong12
Enthusiast
Enthusiast
Jump to solution

Hello Lucd;

As always your suggestion worked!!

thanks again

Norm

Reply
0 Kudos