Apologies, wasn’t sure how to title this. Thanks to Neally, I have a script that somewhat works. The only issue I’m having is exporting the results for all the PC’s in the list.

$computers = Get-Content \\server\Common\Drives\list.TXT
ForEach ($Computer in $Computers) {
Get-PhysicalDisk |
select-object $computer,FriendlyName,MediaType,HealthStatus,@{n='size';e={[math]::Round($_.size / 1gb)}}|
Export-Csv \\server\Common\Drives\list.csv -NoTypeInformation
}

If I run this script as is, it will only name the bottom entry in the list.TXT file with my PC’s hard drive specifics, so I’m guessing the select-object is incorrect. Could someone assist please? Thank you.

7 Spice ups

easy way → you have to append the CSV

Export-Csv \\server\Common\Drives\list.csv -NoTypeInformation -append

better way → assign output to a variable and then export it

$computers = Get-Content "\\server\Common\Drives\list.TXT"

$report = 
ForEach ($Computer in $Computers) {
    Get-PhysicalDisk |
    select-object $computer,FriendlyName,MediaType,HealthStatus,
    @{n='size';e={[math]::Round($_.size / 1gb)}}
}

$report | Export-Csv "\\server\Common\Drives\list.csv" -NoTypeInformation

oh also

Get-PhysicalDisk

only works on the local machine you run it against, but you want data from remote computers?
that needs a good chunk more code, you need to invoke the command on the remote machine.

e.g.

$computers = Get-Content "\\server\Common\Drives\list.TXT"

$report = 
ForEach ($Computer in $Computers) {
    if(Test-Connection $computer -Count 1 -Quiet){
        $remoteMachine = 
        invoke-command -computername $computer -ScriptBlock {
            Get-PhysicalDisk
        }
        foreach($disk in $remoteMachine){
            [pscustomobject]@{
                ComputerName = $computer
                FriendlyName = $disk.FriendlyName
                MediaType    = $disk.MediaType
                HealthStatus = $disk.HealthStatus
                Size         =[math]::Round($disk.size / 1gb)
            }
        }
    }
    else{
        [pscustomobject]@{
                ComputerName = $computer
                FriendlyName = '-'
                MediaType    = '-'
                HealthStatus = '-'
                Size         = '-'
        }
    }
}

$report |
Export-Csv "\\server\Common\Drives\list.csv" -NoTypeInformation

2 Spice ups

That would explain why it’s only showing my PC’s details, thank you for that. I’ll look into the invoke-command functionality.

Thanks again, Neally, really appreciate your responses. This works beautifully.

Just a small comment

I am not sure what you are doing with this line

select-object $computer,FriendlyName,MediaType,HealthStatus,@{n='size';e={[math]::Round($_.size / 1gb)}}|

Select–object, as you are using it here, filters the properties you add from the original objects, and creates a new property on the fly.

However, using $Computer does not do anything as I suspect a computer name is not a property of the input object.

What are you trying to achieve??