다음을 통해 공유


PowerShell: Disk Space report including used space

Requirement

Need a disk space report including Used Space.

Used space is Total Size - Free Space

How to get it in PowerShell for multiple remote servers?

PowerShell Script

$comp= Get-Content "C:\Temp\Comp.txt"

$diskvalue = @()

foreach($pc in $comp)

{

$diskvalue += Get-WmiObject -Class Win32_logicaldisk -ComputerName $pc -Filter DriveType=3 |

Select SystemName , DeviceID , @{Name=?size(GB)?;Expression={?{0:N1}? -f($_.size/1gb)}}, @{Name=?freespace(GB)?;Expression={?{0:N1}? -f($_.freespace/1gb)}}, @{Name=?UsedSpace(GB)?;Expression={?{0:N2}? -f($_.size - $_.FreeSpace/1gb)}}

$diskvalue | Export-Csv C:\Temp\DiskReport.csv -NoTypeInformation

}

Start-Sleep 5

$from = "MailID"

$to = "MailID"

$smtp = "SMTP NAME"

$subject = "Disk Space Report"

Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv

You can download the full Script from Gallery.