This PowerShell script generates a report of network share usage by enumerating shared folders and their sizes on a specified server. The script is beneficial for system administrators to monitor shared resources and manage storage effectively.
powershell
# Define the target server and share path to analyze
$serverName = "YourServerName" # Replace with your server name
$sharePath = "\\$serverName\*" # Wildcard to search all shares
# Retrieve shared folders from the server
$shares = Get-WmiObject -Class Win32_Share -ComputerName $serverName | Where-Object { $_.Path }
$sharesList = $shares | Select-Object Name, Path, Description
$folderSizes = @()
foreach ($share in $sharesList) {
$totalSize = (Get-ChildItem -Path $share.Path -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
$folderSizes += [PSCustomObject]@{
Name = $share.Name
Path = $share.Path
SizeInMB = [math]::round($totalSize / 1MB, 2)
Description = $share.Description
}
}
# Display the folder sizes in a formatted table
$folderSizes | Format-Table -AutoSize
# Export folder sizes report to a CSV file
$exportPath = "C:\NetworkShareUsageReport.csv"
$folderSizes | Export-Csv -Path $exportPath -NoTypeInformation
Write-Host "Report exported to $exportPath"Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
Ready when you are.
Try ServerEngine free for 7 days.