0

Is there any way to get only numbers from the below output: For example, if I want to save the output in variable I should only get 0,1,2,3,4

PS C:\Users\Administrator> Get-Disk

Number Friendly Name Serial Number                    HealthStatus         OperationalStatus      Total Size Partition
                                                                                                             Style
------ ------------- -------------                    ------------         -----------------      ---------- ----------
0      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
1      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
2      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
3      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
4      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
5      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
6      AWS PVDISK    0000                             Healthy              Online                      30 GB MBR
mklement0
  • 382,024
  • 64
  • 607
  • 775
gary
  • 157
  • 1
  • 3
  • 15

1 Answers1

1

You can use dot notation to access the property, which will return its value as an object or as an array of that object type:

(get-disk).number

You need to surround the cmdlet with brackets so that it executes first, then you are retrieving the specified property of the result.

Alternatively you can get the same result via the Select-Object cmdlet and its -ExpandProperty parameter:

Get-Disk | Select-Object -ExpandProperty Number

By using -ExpandProperty you get the value returned as its property type. If you don't use -ExpandProperty, you instead get the original object type but with just the property (or properties) specified.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Mark Wragg
  • 22,105
  • 7
  • 39
  • 68