Home PowerShell Notes
Post
Cancel

PowerShell Notes

Forms of output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS C:\WINDOWS\system32> Get-PhysicalDisk

Number FriendlyName              SerialNumber         MediaType CanPool OperationalStatus HealthStatus Usage            Size
------ ------------              ------------         --------- ------- ----------------- ------------ -----            ----
0      KINGSTON SA1000M8240G     0026_B728_2177_98E5. SSD       False   OK                Healthy      Auto-Select 223.57 GB
1      Samsung SSD 860 EVO 500GB S3Z1NB0KC99453R      SSD       False   OK                Healthy      Auto-Select 465.76 GB


PS C:\WINDOWS\system32> Get-PhysicalDisk | Format-Table | Out-String

Number FriendlyName              SerialNumber         MediaType CanPool OperationalStatus HealthStatus Usage            Size
------ ------------              ------------         --------- ------- ----------------- ------------ -----            ----
0      KINGSTON SA1000M8240G     0026_B728_2177_98E5. SSD       False   OK                Healthy      Auto-Select 223.57 GB
1      Samsung SSD 860 EVO 500GB S3Z1NB0KC99453R      SSD       False   OK                Healthy      Auto-Select 465.76 GB

Same output in both examples. So we can assume that the default is ‘Format-Table’ and ‘Out-String’

Next shows every field in the object where DeviceID = “1”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
PS C:\WINDOWS\system32> Get-PhysicalDisk | Where-Object {$_.DeviceId -eq "1"} | Format-List | Out-String


ObjectId                         : {1}\\PAUL\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{d529b1cc-d25b-11e8-b11a-806e6f6e6963}:PD:{6bdf959e-3514-0cbc-4d66-21e631f63044}"
PassThroughClass                 :
PassThroughIds                   :
PassThroughNamespace             :
PassThroughServer                :
UniqueId                         : 5002538E40B63434
Description                      :
FriendlyName                     : Samsung SSD 860 EVO 500GB
HealthStatus                     : Healthy
Manufacturer                     :
Model                            : Samsung SSD 860 EVO 500GB
OperationalDetails               :
OperationalStatus                : OK
PhysicalLocation                 : Integrated : Bus 0 : Device 23 : Function 0 : Adapter 1 : Port 0
SerialNumber                     : S3Z1NB0KC99453R
AdapterSerialNumber              :
AllocatedSize                    : 500106813440
BusType                          : SATA
CannotPoolReason                 : Insufficient Capacity
CanPool                          : False
DeviceId                         : 1
EnclosureNumber                  :
FirmwareVersion                  : RVT02B6Q
IsIndicationEnabled              :
IsPartial                        : True
LogicalSectorSize                : 512
MediaType                        : SSD
OtherCannotPoolReasonDescription :
PartNumber                       :
PhysicalSectorSize               : 512
Size                             : 500107862016
SlotNumber                       :
SoftwareVersion                  :
SpindleSpeed                     : 0
StoragePoolUniqueId              :
SupportedUsages                  : {Auto-Select, Manual-Select, Hot Spare, Retired...}
UniqueIdFormat                   : FCPH Name
Usage                            : Auto-Select
VirtualDiskFootprint             : 0
PSComputerName                   :
ClassName                        : MSFT_PhysicalDisk

Now let us show the data in a fancy Windows window:

1
Get-PhysicalDisk | Out-GridView

Desktop View Sortable and searchable

Conversion

1
Get-PhysicalDisk | ConvertTo-Xml

Other Examples:

  • ConvertTo-Json
  • ConvertTo-Csv
  • ConvertTo-Html

ConvertTo-Json is especially useful because it will show nested elements in their entirety:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
PS C:\WINDOWS\system32> Get-PhysicalDisk | Select "SupportedUsages" | Format-List


SupportedUsages : {Auto-Select, Manual-Select, Hot Spare, Retired...}

SupportedUsages : {Auto-Select, Manual-Select, Hot Spare, Retired...}


PS C:\WINDOWS\system32> Get-PhysicalDisk | Select "SupportedUsages" | ConvertTo-Json
[
    {
        "SupportedUsages":  {
                                "value":  [
                                              "Auto-Select",
                                              "Manual-Select",
                                              "Hot Spare",
                                              "Retired",
                                              "Journal"
                                          ],
                                "Count":  5
                            }
    },
    {
        "SupportedUsages":  {
                                "value":  [
                                              "Auto-Select",
                                              "Manual-Select",
                                              "Hot Spare",
                                              "Retired",
                                              "Journal"
                                          ],
                                "Count":  5
                            }
    }
]
This post is licensed under CC BY 4.0 by the author.