MOCs: NinjaOne - Map of Content · Powershell - Map of Content
Production version of the UltraTree disk-space analysis script, adjusted to fix NuGet issues on Windows and to exclude browser credential stores from the scan. Referenced from Useful 3rd Party NinjaOne scripts.
#Requires -Version 5.1
# 1. Disable prompts and configure NuGet
$ProgressPreference = 'SilentlyContinue'
$ConfirmPreference = 'None'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# === EXCLUSION PATHS ===
# Excludes browser credential/profile stores that trigger T1555.003 (Credentials from Web Browsers)
$ExcludePaths = @(
# Chromium-based browsers (Edge, Chrome, Brave, Opera)
"*\AppData\Local\Microsoft\Edge\User Data*",
"*\AppData\Local\Google\Chrome\User Data*",
"*\AppData\Local\BraveSoftware\Brave-Browser\User Data*",
"*\AppData\Local\Opera Software*",
# Firefox
"*\AppData\Roaming\Mozilla\Firefox\Profiles*",
# General credential stores
"*\AppData\Roaming\Microsoft\Credentials*",
"*\AppData\Local\Microsoft\Credentials*",
"*\AppData\Roaming\Microsoft\Protect*"
)
# 2. Install NuGet if needed
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
Install-PackageProvider -Name NuGet -Force -Scope AllUsers -Confirm:$false
}
try {
$moduleName = "UltraTree"
$installed = Get-Module -ListAvailable -Name $moduleName -ErrorAction SilentlyContinue | Sort-Object Version -Descending | Select-Object -First 1
if (-not $installed) {
Write-Output "Installing $moduleName from PowerShell Gallery..."
Install-Module -Name $moduleName -Scope AllUsers -Force -AllowClobber -Confirm:$false
}
else {
$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 -Confirm:$false
}
}
# 3. Import the module
Import-Module $moduleName -Force -ErrorAction Stop
# 4. Run the analysis
$results = Get-FolderSizes -AllDrives -FindDuplicates -MaxDepth 5 -Top 50
# 5. Filter excluded paths from Items
$originalCount = $results.Items.Count
$filteredItems = $results.Items | Where-Object {
$itemPath = $_.Path
$excluded = $false
foreach ($pattern in $ExcludePaths) {
if ($itemPath -like $pattern) {
$excluded = $true
break
}
}
-not $excluded
}
$filteredCount = $originalCount - $filteredItems.Count
Write-Output "Filtered $filteredCount sensitive entries from results"
# 6. Replace Items with filtered list and push to NinjaOne
$results.Items = $filteredItems
$results | ConvertTo-NinjaOneHtml | Ninja-Property-Set-Piped treesize
# 7. Logging
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
}