getting folder size of home directories

I have this script here that pulls info for user out of AD. The last thing I am trying to work out is getting the total size of the users home directory. Any help with this script here would be very much appreciative, thanks.

$filter = "(&(objectcategory=user)(memberof=CN=somegroup,DC=something,dc=com))"
$ds = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
$ds.pagesize = 1000
$ds.Findall() |
Select-Object `
    @{n='Name';e={ $_.Properties['name'][0] }},
    @{n='homedirectory';e={ $_.Properties['homedirectory'][0] }},
    @{n='LastLogonTimeStamp';e={ [DateTime]::FromFileTime($_.Properties["lastlogontimestamp"][0]) }},
    @{n='OU';e={ $_.Properties['distinguishedname'][0] -Replace "CN=$($_.Properties['cn'][0])," }} |
   
    export-csv info.csv -noTypeInformation
techdriveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gcitronCommented:
Try to add this column in select-object:  
@{n='homedirectorysize';e={  (Get-ChildItem $_.Properties['homedirectory'][0] -recurse | Measure-Object -property length -sum ).sum }}
0
techdriveAuthor Commented:
this did not work. Did you test this?
0
gcitronCommented:
I tested in the form:
$env:userprofile | select @{n='homedirectorysize';e={  (Get-ChildItem $_ -recurse | Measure-Object -property length -sum ).sum }}

In the homeDirectory property is the local path for userprofile, so this script is usable on a TS, where you get homedirectorysize for all profiles on that server. If you want homedirectorysize on workstations, then you must know on what workstations the user has a profile and try something like
("\\$computername\" + ($_.Properties['homedirectory'][0]  -replace ":", "$"))
instead of $_.Properties['homedirectory'][0] ...
0
Challenges in Government Cyber Security

Has cyber security been a challenge in your government organization? Are you looking to improve your government's network security? Learn more about how to improve your government organization's security by viewing our on-demand webinar!

techdriveAuthor Commented:
These directory sizes are not on workstations, they are on the network. This is pulling from the home directory attribute in AD. I was just wondering if there was a way to calculate the folder size being presented in the select object statement.
0
gcitronCommented:
Ok, that information is stored as I konw in "profilePath", not in "homeDirectory". Anyway, if your script display the path like "\\server\share\path\username", you can calculate the size of that folder with (Get-ChildItem "\\server\share\path\username" -recurse | Measure-Object -property length -sum ).sum .
0
techdriveAuthor Commented:
Yes, understood and if I were doing this as a seperate piece it would work fine. My question is how do I incorporate this into the script above.
0
gcitronCommented:
$filter = "(&(objectcategory=user)(memberof=CN=somegroup,DC=something,dc=com))"
$ds = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
$ds.pagesize = 1000
$ds.Findall() |
Select-Object `
    @{n='Name';e={ $_.Properties['name'][0] }},
    @{n='homedirectory';e={ $_.Properties['homedirectory'][0] }},
    @{n='homedirectorysize';e={  (Get-ChildItem $_.Properties['homedirectory'][0] -recurse | Measure-Object -property length -sum ).sum }},
    @{n='LastLogonTimeStamp';e={ [DateTime]::FromFileTime($_.Properties["lastlogontimestamp"][0]) }},
    @{n='OU';e={ $_.Properties['distinguishedname'][0] -Replace "CN=$($_.Properties['cn'][0])," }} |
   
    export-csv info.csv -noTypeInformation
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.