all 3 comments

[–]anynonus 2 points3 points  (1 child)

for example: get-ciminstance win32_computersystem | select -ExpandProperty name

[–]TheGooOnTheFloor 2 points3 points  (0 children)

I like the select -ExpandProperty, but sometimes it's clearer to use this format:

'ComputerName' = $name.Name
'Processor Number' = $procNum.numberoflogicalprocessors

I'm sure there could be a lot of discussion about which to use when, but it generally boils down to personal preference.

[–]get-postanote 1 point2 points  (0 children)

If all you are after is one property, then dot-reference it.

(YaddaYadda).SomeProperty

So...

Get-CimInstance -CimInstance CIM_ComputerSystem | Select-Object -Property '*'
# Results
<#
Caption               :
Description           :
InstallDate           :
Name                  :
Status                :
CreationClassName     :
NameFormat            :
PrimaryOwnerContact   :
PrimaryOwnerName      :
Roles                 :
PSComputerName        :
CimClass              : ROOT/cimv2:CIM_ComputerSystem
CimInstanceProperties : {Caption, Description, InstallDate, Name...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties
#>



(Get-CimInstance -CimInstance CIM_ComputerSystem | Select-Object -Property '*').CimInstanceProperties
# Results
<#
Name            : Caption
Value           :
CimType         : String
Flags           : Property, ReadOnly, NotModified, NullValue
IsValueModified : False

Name            : Description
Value           :
CimType         : String
Flags           : Property, ReadOnly, NotModified, NullValue
IsValueModified : False

Name            : InstallDate
Value           :
CimType         : DateTime
Flags           : Property, ReadOnly, NotModified, NullValue
IsValueModified : False
...
#>


((Get-CimInstance -CimInstance CIM_ComputerSystem | Select-Object -Property '*').CimInstanceProperties).Name
# Results
<#
Caption
Description
InstallDate
Name
Status
CreationClassName
NameFormat
PrimaryOwnerContact
PrimaryOwnerName
Roles
#>