Technical Article

Drive Space

,

Create a .txt file with all of your server name and save it in a safe location, like C:\ServerList.

Copy the above script and update it with your desire location for the output file, Like C:\HardDriveSpaceDetail.txt

Attached that file to your email and send it to your boss. I used Gmail as the SMTP, but you should use your corporate email service or SMTP.

Create a windows task to run the PS script before you have your morning coffee.

#Hard drive space detail
Clear-Host
$OutArray = @()
$serverList = Get-Content 'C:\ServerList.txt'
foreach($svr in $serverList )
{
$server = Get-WmiObject -ComputerName $svr -class win32_volume  | select @{LABEL='Server';EXPRESSION={($_.SystemName)}},`
                                                              @{LABEL='Drive';EXPRESSION={$_.DriveLetter}},` 
                                                              @{LABEL='Label';EXPRESSION={$_.label}},`
                                                              @{LABEL='Capacity (MB)';EXPRESSION={[decimal]("{0:N0}" -f($_.Capacity/1mb))}},`
                                                              @{LABEL='Free Space (MB)';EXPRESSION={[decimal]("{0:N0}"-f($_.freeSpace/1mb))}},`
                                                              @{LABEL='% Free';EXPRESSION={("{0,6:P0}" -f(($_.freeSpace/1mb) / ($_.Capacity/1mb)))}}| Format-Table -AutoSize -Wrap;
$OutArray+= $server;
$server = $null
}
$outarray | Out-File 'C:\HardDriveSpaceDetail.txt';

$From = "mashrur.shuvo@gmail.com"
$To = "xxxxxxx@yyyyyy.com"
$Subject = "HardDriveSpaceDetail"
$Body = "Please Check the following .txt attachment. Its not a virus, its your detail Hard drive space report of all servers."
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$attachment = 'C:\HardDriveSpaceDetail.txt'
Send-MailMessage -From $From -to $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Attachments $attachment `
-Credential (Get-Credential)

Rate

1 (3)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (3)

You rated this post out of 5. Change rating