Author Posts

February 11, 2017 at 3:09 am

Hello

I am trying to show healthy physical disks using one of the following

Get-PhysicalDisk select Status -eg healthy
Get-PhysicalDisk select status -HealthStatus
Get-PhysicalDisk select status -healthy

but I am getting parameter errors in ISE.

Should I not be using Select?

Thank you.

February 11, 2017 at 7:00 am

Hi Steve,

To filter (only show) healthy disks you'll need to use the Where-Object cmdlet (Where) instead of Select-Object (Select).

# PowerShell v3.0 and later
Get-PhysicalDisk | Where-Object Status -eq 'Healthy'
Get-PhysicalDisk | Where-Object { $PSItem.Status -eq 'Healthy' }

# PowerShell v1.0 and later
Get-PhysicalDisk | Where-Object { $_.Status -eq 'Healthy' }

The purpose of Where-Object is to filter objects passing through the pipeline. Select-Object can be used to select properties of objects passing through the pipeline.

Get-PhysicalDisk | Where-Object Status -eq 'Healthy' | Select-Object -Property FriendlyName, Status, Size

I think it would be best for you to invest your time and to go through the PowerShell Jumpstart on the Microsoft Virtual Academy.

https://mva.microsoft.com/liveevents/powershell-jumpstart

I hope above helps.

All the Best,
Daniel

February 11, 2017 at 7:17 am

Thank you, Daniel

In PS5 using

Get-PhysicalDisk | Where-Object Status -eq 'Healthy'

I now get no errors.

Thank you too, for the link. I will browse there now!

Steve

Not sure how I thank you here?

February 11, 2017 at 7:27 am

Just writing a comment saying "Thank you" as you did is enough here.

Depending on your mode of learning the book "Learn PowerShell 3 in a Month of Lunches" is very good and highly recommended, and a great investment. The book is completely applicable to v4 and v5 because these versions only added advanced concepts which wouldn't have been covered in the book anyway.

February 11, 2017 at 7:32 am

Thanks again, I will have a search!