Link to home
Start Free TrialLog in
Avatar of ITguy565
ITguy565Flag for United States of America

asked on

Powershell Scripting Issue : Folder Size Report

Experts,

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      
}

Open in new window


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
Avatar of ITguy565
ITguy565
Flag of United States of America image

ASKER

Going to leave this code out here.. But I did figure it out,
ASKER CERTIFIED SOLUTION
Avatar of ITguy565
ITguy565
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial