显示输出中的唯一值

时间:2019-04-15 18:09:56

标签: powershell

我有显示来自主机的驱动程序信息的脚本。但是我正在寻找唯一的值输出没有重复的名称设备。

条件:- 如果名称设备相似但版本不同。我也想同时保留名称设备和版本信息。

Name-Device                               Device-Class                              Module                                    Version                                 
-----------                               ------------                              ------                                    -------                                 
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.16, Build: 2494789, Int...
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...

代码:-

$host.system.module.get($hosthard.ModuleName) |
Select @{N='Name-Device';E={$hosthard.DeviceName}},@{N='Device-Class';E={$hosthard.DeviceClassName}},Module,Version | unique -OnType

输出:-

Name-Device                               Device-Class                              Module                                    Version                                 
-----------                               ------------                              ------                                    -------                                 
Lewisburg SATA AHCI Controller            SATA controller                           ahci                                      Version 3.0-26vmw, Build: 5050593, In...
Lewisburg USB 3.0 xHCI Controller         USB controller                            xhci                                      Version 1.0, Build: 4600944, Interfac...
Lewisburg PCI Express Root Port #1        PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Lewisburg PCI Express Root Port #5        PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
x1 PCIe Gen2 Bridge[Pilot4]               PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Sky Lake-E PCI Express Root Port 1A       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC 1300 PCIe Upstream Port               PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC PCIe Downstream Port                  PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC PCIe Upstream Port                    PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC PCIe Downstream Port                  PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC FCoE HBA Driver                 Fibre Channel                             fnic                                      Version 1.6.0.34, Build: 2494585, Int...
Cisco VIC FCoE HBA Driver                 Fibre Channel                             fnic                                      Version 1.6.0.34, Build: 2494585, Int...
Sky Lake-E PCI Express Root Port 1C       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Cisco 12G Modular Raid Controller with... RAID bus controller                       lsi_mr3                                   7.701.14.00-1OEM.600.0.0.2768847        
Sky Lake-E PCI Express Root Port 1C       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Sky Lake-E PCI Express Root Port 1D       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            

我正在寻找如下输出:-我的意思是唯一值不重复。

        Name-Device                               Device-Class                              Module                                    Version                                 
-----------                               ------------                              ------                                    -------                                 
Lewisburg SATA AHCI Controller            SATA controller                           ahci                                      Version 3.0-26vmw, Build: 5050593, In...
Lewisburg USB 3.0 xHCI Controller         USB controller                            xhci                                      Version 1.0, Build: 4600944, Interfac...
Lewisburg PCI Express Root Port #1        PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
x1 PCIe Gen2 Bridge[Pilot4]               PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Sky Lake-E PCI Express Root Port 1A       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC 1300 PCIe Upstream Port               PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC PCIe Downstream Port                  PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
VIC PCIe Upstream Port                    PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Cisco VIC Ethernet NIC                    Ethernet controller                       enic                                      Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC FCoE HBA Driver                 Fibre Channel                             fnic                                      Version 1.6.0.34, Build: 2494585, Int...
Sky Lake-E PCI Express Root Port 1C       PCI bridge                                vmkernel                                  Version Releasebuild-5050593            
Cisco 12G Modular Raid Controller with... RAID bus controller                       lsi_mr3                                   7.701.14.00-1OEM.600.0.0.2768847        
Sky Lake-E PCI Express Root Port 1C       PCI bridge                                vmkernel                                  Version Releasebuild-5050593

1 个答案:

答案 0 :(得分:0)

您可以从Name-Device

中删除尾随的十六进制值和#号。

使用Sort-Object-Unique参数

| Sort-Object {($_.'Name-Device' -split ' [\d#a-f]{2,}$')[0]},Version -Unique

那将返回:

Name-Device                               Device-Class        Module   Version
-----------                               ------------        ------   -------
Cisco 12G Modular Raid Controller with... RAID bus controller lsi_mr3  7.701.14.00-1OEM.600.0.0.2768847
Cisco VIC Ethernet NIC                    Ethernet controller enic     Version 2.3.0.14, Build: 2494585, Int...
Cisco VIC FCoE HBA Driver                 Fibre Channel       fnic     Version 1.6.0.34, Build: 2494585, Int...
Lewisburg PCI Express Root Port #1        PCI bridge          vmkernel Version Releasebuild-5050593
Lewisburg SATA AHCI Controller            SATA controller     ahci     Version 3.0-26vmw, Build: 5050593, In...
Lewisburg USB 3.0 xHCI Controller         USB controller      xhci     Version 1.0, Build: 4600944, Interfac...
Sky Lake-E PCI Express Root Port 1D       PCI bridge          vmkernel Version Releasebuild-5050593
VIC 1300 PCIe Upstream Port               PCI bridge          vmkernel Version Releasebuild-5050593
VIC PCIe Downstream Port                  PCI bridge          vmkernel Version Releasebuild-5050593
VIC PCIe Upstream Port                    PCI bridge          vmkernel Version Releasebuild-5050593
x1 PCIe Gen2 Bridge[Pilot4]               PCI bridge          vmkernel Version Releasebuild-5050593