using
System;
System.Collections.Generic;
System.Collections.ObjectModel;
System.Linq;
System.Text;
System.Web;
Microsoft.SharePoint;
Microsoft.Office.Server;
Microsoft.Office.Server.UserProfiles;
namespace
RahulCheckEffectivePermissionsInAllWebs
{
class
Program
static
void
Main(
string
[] args)
try
Console.WriteLine(
"This tool will chcek the effective permissions of a user"
);
"Please enter the url of the site collection"
String url = Console.ReadLine();
"Please enter the username of the user"
String userName = Console.ReadLine();
(SPSite site =
new
SPSite(url))
ServerContext serverContext = ServerContext.GetContext(site);
UserProfileManager userProfileManager =
UserProfileManager(serverContext);
UserProfile userProfile = userProfileManager.GetUserProfile(userName);
String userLogin = userProfile[PropertyConstants.AccountName].Value.ToString();
SPWebCollection webs = site.AllWebs;
foreach
(SPWeb web
in
webs)
SPPermissionInfo permissionInfo = web.GetUserEffectivePermissionInfo(userLogin);
Collection<SPRoleAssignment> roles = permissionInfo.RoleAssignments;
"Now checking the permissions of the user "
+ userLogin +
" "
+
"in the site "
+ web.Url);
for
(
int
i = 0; i < roles.Count; i++)
SPRoleDefinitionBindingCollection bRoles = roles[i].RoleDefinitionBindings;
(SPRoleDefinition roleDefinition
bRoles)
if
(roles[i].Member.ToString().Contains(
'\\'
))
"The User "
" has direct permissions "
+ roleDefinition.Name);
}
else
" has permissions "
+ roleDefinition.Name +
" given via "
+ roles[i].Member.ToString());
"Execution Completed"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Richard Mueller edited Revision 3. Comment: Changed tag "SPS 2010" to "SharePoint 2010", added tag
Fernando Lugão Veltem edited Revision 2. Comment: remove en-us from title
Ed Price - MSFT edited Revision 1. Comment: Capitalizing the "P" in "SharePoint"
Craig Lussier edited Original. Comment: added en-US to tags and title
good!!
helping