-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-DiskSpace.ps1
19 lines (16 loc) · 968 Bytes
/
Get-DiskSpace.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
param($computer,[switch]$homeSVRs,[switch]$delprof,[switch]$lowonly)
if($homeSVRs){
$svr = get-xaapplicationreport "Home" | select -expand servernames | sort
}
elseif($computer){$svr = $computer}
else{$svr = "."}
$logicalDisk = gwmi win32_LogicalDisk -computer $svr -cred $(get-credential)| ?{$_.drivetype -eq 3} | select @{Name="Server";Expression={$_.__SERVER}},@{Name="Drive";Expression={$_.DeviceID}},@{Name="SizeGB";Expression={"{0} GB" -f [math]::round($_.Size/1024/1024/1024,3)}},@{Name="UsedGB";Expression={"{0} GB" -f [math]::round(($_.Size-$_.FreeSpace)/1024/1024/1024,3)}},@{Name="FreeGB";Expression={"{0} GB" -f [math]::round($_.FreeSpace/1024/1024/1024,3)}},@{Name="PercentFree";Expression={"{0}%" -f [math]::round(100*$_.FreeSpace/$_.Size,1)}}
$logicalDisk | %{
if($homeSVRs){
if($_.Drive -eq "D:" -and $_.FreeSpace -le 2.5){
$_
if($delprof){invoke-command -computer $_.Server -script {delprof /q /i /d:3} -asjob}
}
}
else{$_}
}