forked from szymonos/PSAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisksFreeSpace.ps1
30 lines (26 loc) · 1.38 KB
/
DisksFreeSpace.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
.Synopsis
Scripc checking free space on remote servers
.Example
.\DriveFreeSpace.ps1
#>
$prodServers = 'server1', 'server2'
$diskSize = @()
foreach ($server in $prodServers) {
$diskSize += Invoke-Command -ComputerName $server -Credential $credsadm -ScriptBlock {
[System.IO.DriveInfo]::GetDrives() |
Where-Object { $_.VolumeLabel -notlike '*dtc' -and $_.VolumeLabel -notlike '*wtns' -and $_.DriveType -eq 'Fixed' } |
Select-Object -Property Name, DriveFormat, IsReady, AvailableFreeSpace, TotalSize, VolumeLabel
}
}
$diskSize | Format-Table -AutoSize -Property PSComputerName, Name, VolumeLabel, @{Name = "Total (GB)"; Expression = { "{0:N0}" -f ($_.TotalSize / 1GB) }; Align = "Right" }, @{Name = "Available (GB)"; Expression = { "{0:N0}" -f ($_.AvailableFreeSpace / 1GB) }; Align = "Right" }, @{Name = "Free %"; Expression = { "{0:N0}" -f ($_.AvailableFreeSpace / $_.TotalSize * 100) }; Align = "Right" }
foreach ($disk in $diskSize) {
$pctFree = [math]::Round($disk.AvailableFreeSpace / $disk.TotalSize * 100, 1)
if ($pctFree -lt 10) {
Write-Host "ERROR : $pctFree% free on $($disk.PSComputerName) disk $($disk.Name) ($($disk.VolumeLabel))" -ForegroundColor Red
}
elseif ($pctFree -ge 10 -and $pctFree -lt 20) {
Write-Warning "$pctFree% free on $($disk.PSComputerName) disk $($disk.Name) ($($disk.VolumeLabel))"
}
}
Write-Output ''