0

first post here. I am trying to make a script that will only format mechanical hard drives on a computer and leaves the SSD(s) as they are. Can someone explain why the following occurs:

PS C:\Users\hekke> Get-PhysicalDisk | Where-Object -Property mediatype -EQ hdd

gives me the output:

Number FriendlyName           SerialNumber    MediaType CanPool OperationalStatus HealthStatus Usage            Size
------ ------------           ------------    --------- ------- ----------------- ------------ -----            ----
0      WDC WD10TPVT-00U4RT1   WD-WXH1A81P7778 HDD       False   OK                Healthy      Auto-Select 931.51 GB
1      WDC WD5000LPVX-22V0TT0 WD-WX71AA4H4EV2 HDD       False   OK                Healthy      Auto-Select 465.76 GB

But when I do:

PS C:\Users\hekke> Get-PhysicalDisk | Where-Object -Property mediatype -EQ hdd | Select-Object number

it only gives me the empty number table:

number
------

I am new to powershell, thanks in advance to anyone willing to help

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Hekke
  • 9
  • 1

1 Answers1

1

This is a case of PowerShell trying too hard to make things user friendly. The reason you don't get a Number property is that it doesn't exist. If you pipe that to | Get-Member you'll see the list of properties, and Number is nowhere to be found. It is a calculated property that is created when that object type is output to a table with its default output formatting. What you can use instead is DeviceId as such:

Get-PhysicalDisk | Where-Object -Property mediatype -EQ hdd | Select-Object DeviceId

That should line up just fine with what you saw in the first table.

mklement0
  • 382,024
  • 64
  • 607
  • 775
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56