ITguy565
asked on
Powershell Scripting Issue : Folder Size Report
Experts,
Powershell scripting issue :
Most of this code functions, however, I am running into an issue retrieving the rootlevel folder $loc 's size in the $colresults object.
Any chance someone can assist with this :
- Thanks
Powershell scripting issue :
Function get-spaceusagereport($loc){
set-location $loc
$colItems = Get-ChildItem $loc | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
$colresults = @()
foreach ($i in $colItems) {
try {
write-host "Processing .... $i"
$subFolderItems = @()
$subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
$object = ""|select Fullpath, SpaceUsed, rawspace
$object.FullPath = $i.FullName
$object.SpaceUsed = "{0:N2}" -f $($subfolderitems.sum / 1MB) + " MB"
$object.rawspace = $($subfolderitems.sum / 1MB)
$colresults += $object
}
catch {
write-host "Could Not Access $i"
}
}
#$object.Fullpath = $loc
#$rootFolder = Get-ChildItem $($loc) -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
#$object.spaceused = "{0:N2}" -f $($subfolderitems.sum / 1MB) + " MB"
#$object.rawspace = $($subfolderitems.sum / 1MB)
#$colresults += $object
write-host "The Top Space Using Folders are :"
$($colresults|sort-object rawspace -Descending|select -first 5)|select FullPath, SpaceUsed
}
Most of this code functions, however, I am running into an issue retrieving the rootlevel folder $loc 's size in the $colresults object.
Any chance someone can assist with this :
- Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER