My last post had a simple script for dumping out all the users in a site collection – (the post said farm, but that wasn’t the code that got posted)
I’ve had a chance (and need) to work with the script and made a few nice improvements
- There are a few commented out if statements you can uncomment if you want to search for a particular user or domain
- The color output and indentation is a little better in this script
- The code dumps all it’s output into a single CSV file you can import into Excel, Access or any tool of your likeing
That last bullet point really can’t be under estimated.
Some ideas:
- You can save the list as a reference of what your group memberships were on a given day (note I didnt say permissions)
- You could import the list into access or excel, and do queries all day long
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #getalluserinaSiteCollection Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue $iissite = get-spwebapplication | where {$_.url -eq "http://www.yoursite.com/"} $iissite $header = "type,user,group,weburl,webname" $header | out-file filename.txt foreach ($SiteCollection in $iissite.sites) { write-host $SiteCollection -foregroundcolor Blue foreach ($web in $SiteCollection.Allwebs) { write-host " " $web.url $web.name "users:" -foregroundcolor yellow # Write-host " " $web.users | select name foreach ($userw in $web.users) { #if ($userw -like "Domain\*") #{ write-host " " $userw -foregroundcolor white #$msg = ("{0},{1} user:{2}" -f $web.url,$web.name, $userw) $msg = ("RootUser,{0},-,{1},{2}" -f $userw, $web.url,$web.name) $msg | out-file filename.txt -append # } } foreach ($group in $web.Groups) { Write-host " " $web.url $group.name: -foregroundcolor green foreach ($user in $group.users) { # if ($user -like "DOMAIN\*") #{ Write-host " " $user -foregroundcolor white #$msg = ("{0},{1},group:{2}, user:{3}" -f $web.url, $web.name, $group, $user) $msg = ("GroupUser,{0},{1},{2},{3}" -f $user, $group, $web.url, $web.name) $msg | out-file filename.txt -append #} } } } } |
