首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较PowerCLI中的两个对象

比较PowerCLI中的两个对象
EN

Stack Overflow用户
提问于 2015-08-05 15:19:47
回答 1查看 263关注 0票数 2

如果问题不完全正确,我很抱歉,因为我不确定这个问题的正确措辞/语法.

代码语言:javascript
复制
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

如何比较和匹配要输出的"SelectedOS“和"InstalledOS”的数据。

因此,例如,当前脚本将输出:

代码语言:javascript
复制
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)

不过,我只想看到:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-05 16:21:16

如果我读得对,您希望比较并只显示"SelectedOS“和"InstalledOS”相同的机器。要做到这一点,您需要在-eq语句中使用Where。如下所示:

代码语言:javascript
复制
Where { $_.Guest.GuestFullname -eq $_.Summary.Config.GuestFullName }

所以你的代码变成了。

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31836516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档