Question re Get-PhysicalDisk

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Steve Steve 5 months, 2 weeks ago.

  • Author
    Posts
  • #63980
    Profile photo of Steve
    Steve
    Participant

    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.

  • #63983
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    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

  • #63986
    Profile photo of Steve
    Steve
    Participant

    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?

  • #63989
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    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.

  • #63992
    Profile photo of Steve
    Steve
    Participant

    Thanks again, I will have a search!

You must be logged in to reply to this topic.