$computername = Read-Host "Enter a computername" $Query = "Select * from win32_logicaldisk where drivetype=3" Get-WmiObject -Query $Query -ComputerName $computername | Select-Object -property DeviceID,Size,Freespace, @{Name="PercentFree";Expression = {$_.freespace/$_.size}}
Get all fixed logical disks from a remote computer. Select the computername, drive letter, size in GB, free space and percent free space and export to a CSV file.
https://jeffhicks.substack.com/p/the-value-of-objects
The Value of Objects
Try:
$computername = Read-Host "Enter a computername" $Query = "Select * from win32_logicaldisk where drivetype=3" Get-WmiObject -Query $Query -ComputerName $computername | Select-Object -property DeviceID,Size,Freespace, @{Name="PercentFree";Expression = {$_.freespace/$_.size}}
Get all fixed logical disks from a remote computer. Select the computername, drive letter, size in GB, free space and percent free space and export to a CSV file.
Try:
@{Name="PercentFree";Expression = {"{0:p2}" -f ($_.freespace/$_.size)}}
Try:@{Name="PercentFree";Expression = {[math]::round(($_.freespace/$_.size)*100,2)}}
Functions write Objects
Okay...
... but this is better: