NinjaOne Integration¶
UltraTree is designed for seamless integration with NinjaOne RMM. The HTML output is optimized for WYSIWYG custom fields with responsive design, charts, and color-coded status indicators.
Overview¶
The integration allows you to:
- Automatically scan disk usage on all managed devices
- Display beautiful HTML reports in NinjaOne device details
- Schedule scans on a recurring basis
Prerequisites¶
- NinjaOne agent installed on target devices
- UltraTree module installed system-wide (see Installation)
- Custom field configured (WYSIWYG/HTML type)
Step 1: Create the Custom Field¶
- Log into NinjaOne
- Go to Administration → Devices → Role Custom Fields
- Click Add to create a new field
- Configure the field:
- Label:
TreeSize(or your preferred display name) - Name:
treesize(this is the script reference name) - Type: WYSIWYG (HTML)
- Scripts: Read/Write
- Click Save
- Assign the field to appropriate device roles
Important
The field type must be WYSIWYG (HTML). Plain text fields will show raw HTML code instead of the rendered report.
Step 2: Create the Script¶
Basic Script¶
Minimal script for quick deployment:
# UltraTree NinjaOne Script - Install if needed, then run
if (-not (Get-Module -ListAvailable -Name UltraTree)) {
Install-Module -Name UltraTree -Scope AllUsers -Force -AllowClobber
}
Import-Module UltraTree -Force
$results = Get-FolderSizes -AllDrives -FindDuplicates -MaxDepth 5 -Top 50
$html = $results | ConvertTo-NinjaOneHtml
# Set the custom field (change 'treesize' to match your field name)
$html | Ninja-Property-Set-Piped treesize
Production Script (With Error Handling)¶
Production-ready script with error handling and logging:
#Requires -Version 5.1
#Requires -RunAsAdministrator
try {
# Install module if not present
if (-not (Get-Module -ListAvailable -Name UltraTree)) {
Write-Output "Installing UltraTree from PowerShell Gallery..."
Install-Module -Name UltraTree -Scope AllUsers -Force -AllowClobber
}
Import-Module UltraTree -Force -ErrorAction Stop
# Run the scan and set custom field
$results = Get-FolderSizes -AllDrives -FindDuplicates -MaxDepth 5 -Top 50
$results | ConvertTo-NinjaOneHtml | Ninja-Property-Set-Piped treesize
# Log summary
Write-Output "Scan complete: $($results.TotalFiles) files, $($results.TotalFolders) folders"
if ($results.TotalDuplicateWasted -gt 0) {
$wastedGB = [math]::Round($results.TotalDuplicateWasted / 1GB, 2)
Write-Output "Duplicate waste: ${wastedGB} GB"
}
exit 0
}
catch {
Write-Error "UltraTree failed: $_"
exit 1
}
Production Script (With Auto-Update)¶
Automatically updates to the latest version from PowerShell Gallery:
#Requires -Version 5.1
#Requires -RunAsAdministrator
try {
$moduleName = "UltraTree"
$installed = Get-Module -ListAvailable -Name $moduleName | Sort-Object Version -Descending | Select-Object -First 1
if (-not $installed) {
# First-time install
Write-Output "Installing $moduleName from PowerShell Gallery..."
Install-Module -Name $moduleName -Scope AllUsers -Force -AllowClobber
}
else {
# Check for updates
$latest = Find-Module -Name $moduleName -ErrorAction SilentlyContinue
if ($latest -and $latest.Version -gt $installed.Version) {
Write-Output "Updating $moduleName from $($installed.Version) to $($latest.Version)..."
Update-Module -Name $moduleName -Force
}
}
Import-Module $moduleName -Force -ErrorAction Stop
# Run the scan and set custom field
$results = Get-FolderSizes -AllDrives -FindDuplicates -MaxDepth 5 -Top 50
$results | ConvertTo-NinjaOneHtml | Ninja-Property-Set-Piped treesize
# Log summary
Write-Output "Scan complete: $($results.TotalFiles) files, $($results.TotalFolders) folders"
if ($results.TotalDuplicateWasted -gt 0) {
$wastedGB = [math]::Round($results.TotalDuplicateWasted / 1GB, 2)
Write-Output "Duplicate waste: ${wastedGB} GB"
}
exit 0
}
catch {
Write-Error "UltraTree failed: $_"
exit 1
}
Auto-Update Notes
- Requires internet access to check PowerShell Gallery
- If offline, script continues with installed version
- Updates are applied before the scan runs
Lightweight Script (No Duplicates)¶
Faster scan without duplicate detection:
if (-not (Get-Module -ListAvailable -Name UltraTree)) {
Install-Module -Name UltraTree -Scope AllUsers -Force -AllowClobber
}
Import-Module UltraTree -Force
$results = Get-FolderSizes -AllDrives -MaxDepth 3 -Top 30
$html = $results | ConvertTo-NinjaOneHtml
$html | Ninja-Property-Set-Piped treesize
Step 3: Deploy the Script¶
- In NinjaOne, go to Administration → Library → Automation
- Click Add → New Script
- Configure:
- Name:
UltraTree Disk Analysis - Language: PowerShell
- OS: Windows
- Architecture: All
- Paste the script content
- Save the script
Step 4: Schedule the Script¶
- Go to Administration → Policies
- Select the appropriate policy (or create a new one)
- Navigate to Scheduled Scripts
- Add the UltraTree script with:
- Schedule: Weekly (recommended) or Daily
- Run As: System (required for full disk access)
- Time: Off-peak hours recommended
- Apply the policy to target devices
Scheduling Recommendations
- Weekly - Sufficient for most environments
- Daily - For servers or high-activity machines
- Monthly - For stable workstations with little change
Viewing Results¶
- Navigate to any device running the script
- Go to the Details or Custom Fields tab
- Find the TreeSize field
- The HTML report displays:
- Summary statistics
- Per-drive breakdown with charts
- Top folders by size
- File type analysis
- Cleanup suggestions
- Duplicate files (if enabled)
Troubleshooting¶
Module Not Found¶
If the script fails with "Module not found":
# Verify module is installed system-wide
Get-Module -Name UltraTree -ListAvailable
# If not found, install as Administrator
Install-Module -Name UltraTree -Scope AllUsers
HTML Shows as Raw Code¶
- Verify the custom field type is WYSIWYG, not Text
- Re-create the field if needed
Scan Taking Too Long¶
Reduce scope for faster scans:
# Reduce depth and disable duplicates
$results = Get-FolderSizes -AllDrives -MaxDepth 3 -Top 25
Access Denied Errors¶
- Ensure script runs as System
- Check that UltraTree is installed in
$env:ProgramFiles\WindowsPowerShell\Modules
Empty Report¶
- Verify the device has fixed NTFS drives
- Check script output for errors
- Run manually on the device to debug
Example Output¶
The HTML report in NinjaOne displays:
┌─────────────────────────────────────────────┐
│ ULTRATREE DISK ANALYSIS │
├─────────────────────────────────────────────┤
│ 📊 2 Drives │ 📁 1,234 Items │ 🔍 15 │
│ │ │ Dupes │
├─────────────────────────────────────────────┤
│ DRIVE C: - 75% Used (Warning) │
│ ████████████████░░░░░░ 375GB / 500GB │
│ │
│ Top Folders: │
│ ▓▓▓▓▓▓▓▓▓▓ Windows 45 GB │
│ ▓▓▓▓▓▓▓▓ Users 38 GB │
│ ▓▓▓▓▓▓ Program Files 25 GB │
│ │
│ Cleanup Suggestions: │
│ 🗑️ Recycle Bin 2.5 GB │
│ ⏰ Temp Files 1.2 GB │
│ 📦 node_modules 5.8 GB │
└─────────────────────────────────────────────┘
Best Practices¶
- Start with weekly scans - Adjust frequency based on needs
- Use alerts - Don't just collect data, act on it
- Review cleanup suggestions - Automate where safe
- Monitor duplicates - Significant space savings possible
- Test first - Run manually before deploying widely