【问题标题】:Get-WmiObject - show only lines - Description, Service and SystemName - powershellGet-WmiObject - 仅显示行 - 描述、服务和系统名称 - powershell
【发布时间】:2016-05-05 14:07:10
【问题描述】:

我在 powershell 中有这段脚本来列出计算机上的 USB 设备:

Get-WmiObject Win32_USBControllerDevice | Foreach-Object { [Wmi]$_.Dependent }

这是输出的一部分:

__GENUS                     : 2
__CLASS                     : Win32_PnPEntity
__SUPERCLASS                : CIM_LogicalDevice
__DYNASTY                   : CIM_ManagedSystemElement
__RELPATH                   : Win32_PnPEntity.DeviceID="USB\\VID_0424&PID_5534\\5&38E06FA4&0&14"
__PROPERTY_COUNT            : 24
__DERIVATION                : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER                    : OTLB674G
__NAMESPACE                 : root\cimv2
__PATH                      : \\OTLB674G\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_0424&PID_5534\\5&38E06FA4&0&14" 
Availability                :  
Caption                     : Rozbočovač USB 3.0 
ClassGuid                   : {36fc9e60-c465-11cf-8056-444553540000} 
CompatibleID                : {IUSB3\Class_09&SubClass_00&Prot_03, IUSB3\Class_09&SubClass_00, IUSB3\Class_09} 
ConfigManagerErrorCode      : 0 
ConfigManagerUserConfig     : False 
CreationClassName           : Win32_PnPEntity 
Description                 : Rozbočovač USB 3.0 
DeviceID                    : USB\VID_0424&PID_5534\5&38E06FA4&0&14 
ErrorCleared                :  
ErrorDescription            :  
HardwareID                  : {USB\VID_0424&PID_5534&REV_6082} 
InstallDate                 :  
LastErrorCode               :  
Manufacturer                : Intel(R) Corporation 
Name                        : Rozbočovač USB 3.0 
PNPDeviceID                 : USB\VID_0424&PID_5534\5&38E06FA4&0&14 PowerManagementCapabilities     :  
PowerManagementSupported    :  
Service                     : iusb3hub 
Status                      : OK 
StatusInfo                  :  
SystemCreationClassName     : Win32_ComputerSystem 
SystemName                  : OTLB674G 
PSComputerName              : OTLB674G

我知道如何为 Get-service 显示仅过滤正在运行的服务,但我不知道如何仅过滤行 - 将在输出中显示的描述、服务和系统名称。

如果有任何帮助,我将不胜感激。

提前致谢, 约瑟夫

【问题讨论】:

    标签: powershell filter output get-wmiobject


    【解决方案1】:

    只需将输出传送到Select-Object cmdlet 并指定您要选择的属性:

    Get-WmiObject Win32_USBControllerDevice | Foreach-Object {
        [Wmi]$_.Dependent | Select-Object Description, Service, SystemName
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 2016-07-21
      • 2020-09-22
      相关资源
      最近更新 更多