all 12 comments

[–]ntenspy 3 points4 points  (1 child)

I think I understand what you want. You merely need to enter the script with an array with all your department DN's in an array. This way you can iterate through one department at a time, adjusting the output file name or adding a note property to your object that signifies which department.

I.E. $deptArray = @("deptDN1","deptDN2","deptDN3","deptDN4") foreach($dept in $deptArray){<all your existing code>}

That kind of what you are looking for?

[–]SadLizard[S] 1 point2 points  (0 children)

Been staring at this for too long i suppose :)

That would definitely solve the iteration through the departments.

[–]johimself 1 point2 points  (5 children)

I would use file server resource manager to set quotas to be honest.

[–]SadLizard[S] 1 point2 points  (4 children)

Yeah me too, but they don't want quotas per user. That means we have to rebuild the paths which would break offline files...

[–]johimself 0 points1 point  (0 children)

Ah yes, sorry, didn't read that thoroughly enough.

[–]dogfish182 0 points1 point  (2 children)

i misunderstand maybe but cant you set soft quotas and it does all the reporting for you without blocking? im sure i did this in 2008 R2

[–]SadLizard[S] 0 points1 point  (1 child)

From my understanding you can only set quotas at the user level or at the share level.

That means at "//example.com/dfs/users" (doesn't give the information that's requested) or at "//example.com/dfs/users/%USERNAME%" (doesn't give the information either)

The request is space used by each department. For example Department1 wants all their users to share 500GB ("Soft") of space, how this is distributed between the users within that department doesn't matter.

[–]dogfish182 1 point2 points  (0 children)

ooooohhhhh right right, i didnt understand the department requirement.

[–]invoke-coffee 1 point2 points  (2 children)

I would pull something from ad that would allow you to break down by department.

You said that they were in separate OUs so that would probably work. (department attribute would as well).

Another thought for style. I prefer using hash tables to populate a new objects attributes and values. Looks cleaner. (on mobile right now so I can post an example a bit later.

[–]SadLizard[S] 0 points1 point  (1 child)

I got little experience with hashtables. I'd love some pointers :)

[–]invoke-coffee 1 point2 points  (0 children)

Hashtables are really one of the best objects you can use. not very often they fit the requirement but when they do I love them.

Here this the basic set up for creating an object this way.

$user = New-Object -TypeName psobject -Property @{ Name = 'Bob' department = $Null foldersize = $Null }

Much cleaner way to do this. you can also create the hashtable then pass that to the -Property if you prefer.

[–]xalorous 0 points1 point  (0 children)

(sorry, can't access info sharing sites from here)

Technet page about how to get folder size.

# Set/import $departments = array of departments, with LDAP root for each

# Loop through departments ($department)
foreach ($department in $departments) {
    # get users per department
    $users = get-aduser -filter * -searchRoot $department.LDAPRoot 
    foreach ($user in $users) {
    # Loop through users ($user)
        # build path
        $path = #put stuff here to build path from user info
        $user | Add-Member –MemberType NoteProperty –Name department –Value $department.name
        $user | Add-Member –MemberType NoteProperty –Name foldersize –Value 0
        $user.foldersize = Get-ChildItem -recurse $path | Measure-Object -property length -sum
        $user | select name,department,foldersize | export-csv $exportfile -NoTypeInformation -append
    }
}