PowerShell Script to Report SCCM DP Disk Space
I wrote the following script to quickly output how much disk space my SCCM Distribution Points consumed. If you're not running a CAS, you'll want to change line 21 to point to your primary. This requires that you have the Configuration Manager console installed on the machine.
It's not pretty but it did the trick. I'm certainly open to suggestions in the comments.
1# ------------------------------------------------------------------------------------------------------------------------------------------
2#
3# Script Created by Christopher Kibble
4# www.ChristopherKibble.com
5#
6# You are free to copy, modify, distribute, etc. as you see fit. A little recognition would be appreciated, however ;)
7#
8# ------------------------------------------------------------------------------------------------------------------------------------------
9
10Clear-Host
11
12Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
13
14# Create Empty Array to Store Results
15$allDisks = @()
16
17# Get DP List from CAS
18Write-Host "Getting Distribution Point list"
19$startPath = Get-Location
20cd CAS:
21$dp = Get-CMDistributionPoint
22$count = $dp.Count
23
24# Loop Over DPs to Get Disk Info
25$i = 0
26
27$dp | % {
28
29 $i++
30
31 $dpName = $_.NetworkOSPath
32 $dpName = ($dpName).Substring(2,$dpName.Length-2)
33
34 Write-Progress -Activity "Collecting Disk Information" -Status "$dpName ($i/$count)" -PercentComplete (($i/$count)*100)
35
36 $disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType='3'" -ComputerName $dpName
37
38 if ($disks -eq $null) {
39 Write-Host "Error Connecting to $dpName"
40 } else {
41 $allDisks += $disks
42 }
43
44}
45
46$allDisks | % {
47
48 $pctFree = (($_.Freespace/$_.Size)*100)
49 $pctFree = [math]::round($pctFree)
50
51 $sizeGB = ($_.Size/1024/1024/1024)
52 $sizeGB = [math]::Round($sizeGB,2)
53
54 $freeGB = ($_.FreeSpace/1024/1024/1024)
55 $freeGB = [math]::Round($freeGB,2)
56
57 $_ | Add-Member -MemberType NoteProperty -Name PctFree -Value $pctFree -Force
58 $_ | Add-Member -MemberType NoteProperty -Name SizeGB -Value $sizeGB -Force
59 $_ | Add-Member -MemberType NoteProperty -Name FreeGB -Value $freeGB -Force
60
61}
62
63$allDisks = $allDisks | ? { $_.SizeGB -gt 10 }
64
65Write-Host "All Disks:"
66$allDisks | FT PSComputerName,DeviceID,Size,SizeGB,FreeGB,PctFree
67
68Write-Host "Disks with 20% or Less Free Space:"
69$allDisks | ? { $_.PctFree -le 20 } | Sort PctFree | FT PSComputerName,DeviceID,Size,SizeGB,FreeGB,PctFree
70
71Write-Host "Disks with 10GB or Less Free Space:"
72$allDisks | ? { $_.FreeGB -le 10 } | Sort FreeGB | FT PSComputerName,DeviceID,Size,SizeGB,FreeGB,PctFree