Forum Discussion

dilanmic's avatar
dilanmic
Iron Contributor
Nov 12, 2024

Monitor low disk space for computers

Hi All,

 

We have a requirement to monitor low disk space, particularly on devices with less than 1GB of available space. We were considering creating a custom compliance policy, but this would lead to blocking access to company resources as soon as the device becomes non-compliant. Therefore, we were wondering if there are any other automated methods we could use to monitor the logical disk space (primarily the C drive) using Intune or Microsoft Graph.

 

Thanks in advance,

Dilan

  • Hi,

    You could us a pro active remediation script that triggers on disk space that fall below 1GB. See more info here: https://learn.microsoft.com/en-us/mem/intune/fundamentals/remediations

     

    As example a detection script for this scenario I asked ChatGPT to create (purely as example and needs to be checked and refined further):

     

    $ErrorActionPreference = "Stop"
    
    # Set the threshold (1 GB)
    $thresholdGB = 1
    $thresholdBytes = $thresholdGB * 1GB
    
    # Get the free space on the C: drive (you can change this if needed)
    $drive = Get-PSDrive -Name C
    
    # Check if free space is below threshold
    if ($drive.Free -lt $thresholdBytes) {
        # Return a failure exit code for Intune remediation
        Write-Host "Disk space is below 1 GB. Triggering remediation."
        exit 1
    } else {
        # Disk space is sufficient
        Write-Host "Disk space is above the 1 GB threshold."
        exit 0
    }

     

    You can trigger remediation script to perform something, not sure what you like to do but that should be a second script.

     

    Hope this helps.

     

    Regards,

     

    Sebastiaan

Resources