Some users are placing personal files in the root of C: I want to find out how many files, number and size if on the root of C: excluding any OS files.

this is to be run on windows 7 and windows 10 machines.

$rootofcfiles = @(Get-ChildItem -Path c:\ -Name -Exclude 
templates","program files (x86)","program files", perflogs,est,drivers,recovery,*.ini,*.cab,*.msi)

foreach ($Folder in $rootofcfiles) 
# retrieve all *.txt files in $Folder
#$TxtFiles = Get-ChildItem -Path $Folder  -Include '*'

# get the file count
#$FilesInFolder = $TxtFiles.Count

# calculate folder size
$FolderSize = ($TxtFiles | Measure -Sum Length).Sum

# write folder size to host
$FolderSizeMB = $FolderSize / 1GB
Write-Host "$Folder is $FolderSizeMB GB in size"

The code above does show the files and folders, but it does not show the size and keeps coming up 0

0 Answers