Home > OS >  Powershell Output Braces
Powershell Output Braces

Time:11-27

If I am enter following command:

$ Get-SCClass -Name Microsoft.Windows.Client.Win10.Aggregate.LogicalDisk | Get-SCOMClassInstance | Select-Object Values

The Output looks like this: Powershell Output

How can I grab the first entry (137739444224) of this output? I want to use this number.

Comment of @Olaf was close: Olaf Output

best regards

CodePudding user response:

If one of the properties you get back from the pipeline is an array you can expand it with Select-Object -ExpandProperty <PropertyName> ...

Get-SCClass -Name Microsoft.Windows.Client.Win10.Aggregate.LogicalDisk | 
    Get-SCOMClassInstance | 
        Select-Object -ExpandProperty Values | 
            Select-Object -First 1 | 
                Select-Object -ExpandProperty Value

Another option would be to use the "dot notation"

(Get-SCClass -Name Microsoft.Windows.Client.Win10.Aggregate.LogicalDisk | Get-SCOMClassInstance ).Values[0].Value

CodePudding user response:

So you're trying to expand a property, then get the first element of the array. You can use foreach-object or % to do that as well.

[pscustomobject]@{Values=1377739444224, 'C:', 'NTFS', $false} | % values

1377739444224
C:
NTFS
False


[pscustomobject]@{Values=1377739444224, 'C:', 'NTFS', $false} | % values | 
  select -first 1

1377739444224

Or

[pscustomobject]@{Values=1377739444224, 'C:', 'NTFS', $false} | % {$_.values[0]}

1377739444224
  • Related