2

I apologies if the question is not quite right, as I'm not sure of the correct wording / syntax for this question...

Get-View -ViewType VirtualMachine | Where { $_.Guest.GuestFullname} | Sort Name |Select-Object Name, @{N=”SelectedOS”;E={$_.Guest.GuestFullName}}, @{N=”InstalledOS”;E={$_.Summary.Config.GuestFullName}} | Out-GridView

How would I compare and match the data of "SelectedOS" and "InstalledOS" to be output.

So for example the current script would output:

Name                                                          SelectedOS                                                    InstalledOS
----                                                          ----------                                                    -----------
VM-Demo-CCMIVR-1                                         Microsoft Windows Server 2012 (64-bit)                        Microsoft Windows Server 2012 (64-bit)
VM-Demo-vMCD2                                            Other 2.6.x Linux (32-bit)                                    CentOS 4/5/6 (32-bit)
VM-Inf-CUC-10-5                                          Red Hat Enterprise Linux 6 (64-bit)                           Red Hat Enterprise Linux 6 (64-bit)
VM-Inf-CUCM-10-5                                         Red Hat Enterprise Linux 6 (64-bit)                           Red Hat Enterprise Linux 6 (64-bit)
VM-Inf-DC01                                              Microsoft Windows Server 2012 (64-bit)                        Microsoft Windows Server 2012 (64-bit)

However i only want to see:

Name                                                          SelectedOS                                                    InstalledOS
----                                                          ----------                                                    -----------
VM-Demo-CCMIVR-1                                         Microsoft Windows Server 2012 (64-bit)                        Microsoft Windows Server 2012 (64-bit)
VM-Inf-CUC-10-5                                          Red Hat Enterprise Linux 6 (64-bit)                           Red Hat Enterprise Linux 6 (64-bit)
VM-Inf-CUCM-10-5                                         Red Hat Enterprise Linux 6 (64-bit)                           Red Hat Enterprise Linux 6 (64-bit)
VM-Inf-DC01                                              Microsoft Windows Server 2012 (64-bit)                        Microsoft Windows Server 2012 (64-bit)
StackUser_py
  • 173
  • 1
  • 1
  • 6

1 Answers1

3

If I read you right, you want to compare and only show machines where "SelectedOS" and "InstalledOS" are the same. To do that you need the -eq in your Where statement. Like this:

Where { $_.Guest.GuestFullname -eq $_.Summary.Config.GuestFullName }

So your code becomes.

Get-View -ViewType VirtualMachine | Where { $_.Guest.GuestFullname -eq $_.Summary.Config.GuestFullName } | Sort Name |Select-Object Name, @{N=”SelectedOS”;E={$_.Guest.GuestFullName}}, @{N=”InstalledOS”;E={$_.Summary.Config.GuestFullName}} | Out-GridView
HAL9256
  • 12,384
  • 1
  • 34
  • 46
  • 1
    It might be worth noting that since `SelectedOS -eq InstalledOS` you could probably omit one of the two in the output. That may just be my OCD side coming out though! ;) Good answer by the way – TheMadTechnician Aug 05 '15 at 16:37
  • That did it, it's so obvious now. I was trying to compare the output not the initial query. :( – StackUser_py Aug 05 '15 at 17:44