PowerShell Script to Report SCCM DP Disk Space

Share on:

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


3 comments

Dan D

Nice script! I made use of it, but just an fyi, not sure if the PS command Get-CMDistributionPoint changed recently but for some reason I get nothing when I run this with no parameters. So to get it to work across my two Sites I used this in the beginning:

$dp1 = Get-CMDistributionPoint -SiteCode ZZZ $dp2 = Get-CMDistributionPoint -SiteCode YYY $dp = $dp1 + $dp2

I could have written code to discover all the site codes dynamically and built it that way, but this got the job done for me.

Cheers.

Yuchi

Hi Christopher, Thanks you for this script, it's exactly what I needed. As you say on your script a little recognition is always good so I wanted to show my gratitude for sharing your script. Regards, Yuch..

Chris Kibble

Yuchi, I'm so glad it helped you! Thanks for the comment!