Powershell
$File = "C:\Data.csv"
$Exclusions = ("Administrator", "Default", "Public")
$Profiles = Get-ChildItem -Path $env:SystemDrive"\Users" | Where-Object { $_ -notin $Exclusions }
$AllProfiles = @()
foreach ($Profile in $Profiles) {
$object = New-Object -TypeName System.Management.Automation.PSObject
$FolderSizes = [System.Math]::Round("{0:N2}" -f ((Get-ChildItem ($Profile.FullName + '\Documents'), ($Profile.FullName + '\Desktop') -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB))
$object | Add-Member -MemberType NoteProperty -Name ComputerName -Value $env:COMPUTERNAME.ToUpper()
$object | Add-Member -MemberType NoteProperty -Name Profile -Value $Profile
$Object | Add-Member -MemberType NoteProperty -Name Size -Value $FolderSizes
$AllProfiles += $object
}
[string]$Output = $null
foreach ($Entry in $AllProfiles) {
[string]$Output += $Entry.ComputerName + ',' + $Entry.Profile + ',' + $Entry.Size + [char]13
}
$Output = $Output.Substring(0,$Output.Length-1)
Do {
Try {
$Output | Out-File -FilePath $File -Encoding UTF8 -Append -Force
$Success = $true
} Catch {
$Success = $false
}
} while ($Success = $false)
$File = 'C:\Data.csv'
$Exclusions = 'Administrator', 'Default', 'Public'
Get-ChildItem -Path "$($env:SystemDrive)\Users" -Directory | Where-Object {$Exclusions -notcontains $_.Name} | ForEach-Object {
Try {
$out = [PSCustomObject]([ordered]@{
'ComputerName' = $env:COMPUTERNAME
'Profile' = $_.Name
'Size (MB)' = $null
'Error' = $null
})
$folderSize = (Get-ChildItem -Path "$($_.FullName)\Documents", "$($_.FullName)\Desktop" -File -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
$out.'Size (MB)' = '{0:N2}' -f ($folderSize / 1MB)
} Catch {
$out.Error = $_.Exception.Message
}
$out
} | Export-Csv -NoTypeInformation -Path $File
... "$($_.FullName)\Documents'"
^
$File = 'C:\Data.csv'
$Exclusions = 'Administrator', 'Default', 'Public'
Get-ChildItem -Path "$($env:SystemDrive)\Users" -Directory | Where-Object {$Exclusions -notcontains $_.Name} | ForEach-Object {
Write-Host "Processing $($_.Name) ..."
Try {
$out = [PSCustomObject]([ordered]@{
'ComputerName' = $env:COMPUTERNAME
'Profile' = $_.Name
'Total Size (MB)' = $null
'Documents Size (MB)' = $null
'Created' = (Get-Item -Path $_.FullName).CreationTime.ToString('yyyy-MM-dd HH:mm:ss')
'Error' = $null
})
$totalSize = (Get-ChildItem -Path $_.FullName -File -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
$documentsSize = (Get-ChildItem -Path "$($_.FullName)\Documents", "$($_.FullName)\Desktop" -File -Recurse -ErrorAction Stop | Measure-Object -Property Length -Sum).Sum
$out.'Total Size (MB)' = '{0:N2}' -f ($totalSize / 1MB)
$out.'Documents Size (MB)' = '{0:N2}' -f ($documentsSize / 1MB)
} Catch {
$out.Error = $_.Exception.Message
}
$out
} | Export-Csv -NoTypeInformation -Path $File
$File = 'C:\data.csv'
$Exclusions = 'Administrator', 'Default', 'Public'
#Get-ChildItem -Path "$($env:SystemDrive)\Users" -Directory | Where-Object {$Exclusions -notcontains $_.Name} | ForEach-Object {
Get-ChildItem -Path "\\remotemachine\c$\Users" -Directory | Where-Object {$Exclusions -notcontains $_.Name} | ForEach-Object {
Write-Host "Processing $($_.Name) ..."
Try {
$out = [PSCustomObject]([ordered]@{
'ComputerName' = remote machine
'Profile' = $_.Name
'Total Size (MB)' = $null
'Documents Size (MB)' = $null
'Created' = (Get-Item -Path $_.FullName).CreationTime.ToString('yyyy-MM-dd HH:mm:ss')
'Error' = $null
'Total User folder size' = "{0:N2} MB" -f ((Get-ChildItem C:\users\ -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)
})
$totalSize = (Get-ChildItem -Path $_.FullName -File -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
$documentsSize = (Get-ChildItem -Path "$($_.FullName)\Documents", "$($_.FullName)\Desktop" -File -Recurse -ErrorAction Stop | Measure-Object -Property Length -Sum).Sum
$out.'Total Size (MB)' = '{0:N2}' -f ($totalSize / 1MB)
$out.'Documents Size (MB)' = '{0:N2}' -f ($documentsSize / 1MB)
} Catch {
$out.Error = $_.Exception.Message
}
$out
} | Export-Csv -NoTypeInformation -Path $File