Where to select
Posted by: Richard Siddaway
Using select-object (aliased to select in common usage) to reduce the number of properties passing into further processing is a common aspect of using PowerShell. However, its not the only place we can do it.
Consider this scenario.
We need to test the network client on a number of remote machines. We can use Win32_NetworkClient
PS > Get-WmiObject -Class Win32_NetworkClient
__GENUS : 2
__CLASS : Win32_NetworkClient
__SUPERCLASS : CIM_LogicalElement
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_NetworkClient.Name="Microsoft Windows Network"
__PROPERTY_COUNT : 6
__DERIVATION : {CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : RSLAPTOP01
__NAMESPACE : root\cimv2
__PATH : \\RSLAPTOP01\root\cimv2:Win32_NetworkClient.Name="Microsoft Windows Network"
Caption : Workstation
Description : LanmanWorkstation
InstallDate :
Manufacturer : Microsoft Corporation
Name : Microsoft Windows Network
Status : OK
Now doing this on the local machine is fine but we might want to cut back on the properties returned across the network
PS > Get-WmiObject -Class Win32_NetworkClient -Property Name, Manufacturer, Caption, Description, Status
__GENUS : 2
__CLASS : Win32_NetworkClient
__SUPERCLASS :
__DYNASTY :
__RELPATH : Win32_NetworkClient.Name="Microsoft Windows Network"
__PROPERTY_COUNT : 5
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Caption : Workstation
Description : LanmanWorkstation
Manufacturer : Microsoft Corporation
Name : Microsoft Windows Network
Status : OK
This cuts down the data a bit – obviously for a class such as Win32_ComputerSystem that has a lot more properties you would get a bigger impact
Compare this to using select-object
PS > Get-WmiObject -Class Win32_NetworkClient |
select -Property Name, Manufacturer, Caption, Description, Status
Name : Microsoft Windows Network
Manufacturer : Microsoft Corporation
Caption : Workstation
Description : LanmanWorkstation
Status : OK
OK this looks better BUT remember for a remote machine the filtering happens AFTER the object has been returned.
Locally I would use select and remotely I would think about using –property on Get-WmiObject.
As so often it all depends on what you actually need to do




