Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I got the following code working but it does not give me Roles and Groups. Is the syntax I am using good?

$webUrl = "http://IVR.cisco.com/Sites/Research/VB3343"
$web = Get-SPWeb $webUrl

foreach ($user in $web.SiteUsers){ 
                            #do not list System account sharepoynt\system 
                            if ($user.Loginname.StartsWith("SHAREPOINT\")) {continue} 
                            $data = @{ 
                                        #"Site" = $site.Url 
                                        "Web Url" = $web.Url 
                                        "Web Name" = $web.Title 
                                        "Username" = $user.Loginname 
                                        "Fullname" = $user.Name 
                                        "Roles" = $user.Roles 
                                        "Groups" = $user.Groups 
                            } 
                                    New-Object PSObject -Property $data 
                                    }
$web.dispose()
share|improve this question
    
Do you get the Groups by executing this: $users = $web.SiteUsers $users | % { $_.Groups } –  websch01ar Nov 1 '11 at 19:43
    
That did not help. I am positive someone already has a PS for this. –  Mike conway Nov 2 '11 at 14:51
add comment

2 Answers

up vote 0 down vote accepted

You may have to massage the following code but it works for me.

$webUrl = "http://IVR.cisco.com/Sites/Research/VB3343"
$web = Get-SPWeb $webUrl
Get-SPUser -Web $Web | select UserLogin, @{name="Exlicit given roles";expression={$_.Roles}}, @{name="Roles given via groups";expression={$_.Groups | %{$_.Roles}}},Groups | format-Table -auto
# Get-SPUser -Web $Web | select UserLogin, @{name="Exlicit given roles";expression={$_.Roles}}, @{name="Roles given via groups";expression={$_.Groups | %{$_.Roles}}},Groups | out-gridview
# Get-SPUser -Web $Web | select UserLogin, @{name="Exlicit given roles";expression={$_.Roles}}, @{name="Roles given via groups";expression={$_.Groups | %{$_.Roles}}},Groups | export-csv c:\test.csv
share|improve this answer
add comment

The MSDN article on SPRole (the object returned from SPUser.Roles) says that it is obsolete and you should use the SPRoleDefinition from the SPWeb object instead. The other alternative is SPRoleAssignment.

share|improve this answer
    
Thanks for pitching in. Same thing applies for Groups too? –  Mike conway Nov 2 '11 at 15:28
    
No. If the Groups member isn't giving you what you need, you can try looping through the groups on the SPWeb(s) and check ContainsCurrentUser. There is an almost complete example at chrissyblanco.blogspot.com/2007/07/… which would need a slight update for use in PowerShell –  Tom Resing Nov 2 '11 at 19:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.