Friday, August 1, 2014

Finding Access Rights for Specific User in SharePoint 2007 using Powershell

Today I got a ticket saying, two users are not able to access the SharePoint site and not sure whether they have permissions or not. If they have what kinds of permissions? Since SharePoint 2007 don’t have an option to check, we depend on either on custom code or Powershell.

 

I want to do this pretty quick because of the ticket, I googled for powershell script and found the following site which really works well

 

http://www.sharepointdiary.com/2013/01/audit-user-permissions-in-sharepoint.html

 

Here is the code I got it from above mentioned site and made very few changes to make it dynamic

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") #DECLARE VARIABLES [string]$siteUrl = $args[0] [string]$userToFind = $args[2] #IF MISSING PARM FOR SITE URL, ASK FOR INPUT TO FILL if($args.length -eq 0) { DisplayMissingParametersMessage } function DisplayMissingParametersMessage { #Write-Output "You are missing a parameter for 'Site URL'" $script:siteURL = Read-Host "Enter Site URL" $script:userToFind = Read-Host "Enter User to Find" } #Get All Web Applications Function global:Get-SPWebApplication($WebAppURL) { if($WebAppURL -eq $null) #Get All Web Applications { $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} $WebApps = @() foreach ($websvc in $websvcs) { foreach ($WebApp in $websvc.WebApplications) { $WebApps = $WebApps + $WebApp } } return $WebApps } else #Get Web Application for given URL { return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL) } } Function global:Get-SPSite($url) { if($url -ne $null) { return New-Object Microsoft.SharePoint.SPSite($url) } } Function global:Get-SPWeb($url) { $site= Get-SPSite($url) if($site -ne $null) { $web=$site.OpenWeb(); } return $web } Function GetUserAccessReport($WebAppURL, $SearchUser) { #Get All Site Collections of the WebApp $SiteCollections = Get-SPWebApplication($WebAppURL) $SiteCollections= $SiteCollections.Sites #Write CSV- TAB Separated File) Header "URL `t Site/List `t Title `t PermissionType `t Permissions" | out-file UserAccessReport.csv #Check Whether the Search Users is a Farm Administrator $ca= [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local.Sites[0].RootWeb #Get Central Admin $AdminSite = Get-SPWeb($ca.URL) $AdminGroupName = $AdminSite.AssociatedOwnerGroup.Name $FarmAdminGroup = $AdminSite.SiteGroups[$AdminGroupName] foreach ($user in $FarmAdminGroup.users) { if($user.LoginName -eq $SearchUser) { "$($AdminSite.URL) `t Farm `t $($AdminSite.Title)`t Farm Administrator `t Farm Administrator" | Out-File UserAccessReport.csv -Append } } #Check Web Application Policies $WebApp= Get-SPWebApplication $WebAppURL foreach ($Policy in $WebApp.Policies) { #Check if the search users is member of the group if($Policy.UserName -eq $SearchUser) { #Write-Host $Policy.UserName $PolicyRoles=@() foreach($Role in $Policy.PolicyRoleBindings) { $PolicyRoles+= $Role.Name +";" } #Write-Host "Permissions: " $PolicyRoles "$($WebAppURL) `t Web Application `t $($AdminSite.Title)`t Web Application Policy `t $($PolicyRoles)" | Out-File UserAccessReport.csv -Append } } #Loop through all site collections foreach($Site in $SiteCollections) { #Check Whether the Search User is a Site Collection Administrator foreach($SiteCollAdmin in $Site.RootWeb.SiteAdministrators) { if($SiteCollAdmin.LoginName -eq $SearchUser) { "$($Site.RootWeb.Url) `t Site `t $($Site.RootWeb.Title)`t Site Collection Administrator `t Site Collection Administrator" | Out-File UserAccessReport.csv -Append } } #Loop throuh all Sub Sites foreach($Web in $Site.AllWebs) { if($Web.HasUniqueRoleAssignments -eq $True) { #Get all the users granted permissions to the list foreach($WebRoleAssignment in $Web.RoleAssignments ) { #Is it a User Account? if($WebRoleAssignment.Member.userlogin) { #Is the current user is the user we search for? if($WebRoleAssignment.Member.LoginName -eq $SearchUser) { #Write-Host $SearchUser has direct permissions to site $Web.Url #Get the Permissions assigned to user $WebUserPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebUserPermissions += $RoleDefinition.Name +";" } #write-host "with these permissions: " $WebUserPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($Web.Title)`t Direct Permission `t $($WebUserPermissions)" | Out-File UserAccessReport.csv -Append } } #Its a SharePoint Group, So search inside the group and check if the user is member of that group else { foreach($user in $WebRoleAssignment.member.users) { #Check if the search users is member of the group if($user.LoginName -eq $SearchUser) { #Write-Host "$SearchUser is Member of " $WebRoleAssignment.Member.Name "Group" #Get the Group's Permissions on site $WebGroupPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebGroupPermissions += $RoleDefinition.Name +";" } #write-host "Group has these permissions: " $WebGroupPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($Web.Title)`t Member of $($WebRoleAssignment.Member.Name) Group `t $($WebGroupPermissions)" | Out-File UserAccessReport.csv -Append } } } } } #******** Check Lists with Unique Permissions ********/ foreach($List in $Web.lists) { if($List.HasUniqueRoleAssignments -eq $True -and ($List.Hidden -eq $false)) { #Get all the users granted permissions to the list foreach($ListRoleAssignment in $List.RoleAssignments ) { #Is it a User Account? if($ListRoleAssignment.Member.userlogin) { #Is the current user is the user we search for? if($ListRoleAssignment.Member.LoginName -eq $SearchUser) { #Write-Host $SearchUser has direct permissions to List ($List.ParentWeb.Url)/($List.RootFolder.Url) #Get the Permissions assigned to user $ListUserPermissions=@() foreach ($RoleDefinition in $ListRoleAssignment.RoleDefinitionBindings) { $ListUserPermissions += $RoleDefinition.Name +";" } #write-host "with these permissions: " $ListUserPermissions #Send the Data to Log file "$($List.ParentWeb.Url)/$($List.RootFolder.Url) `t List `t $($List.Title)`t Direct Permissions `t $($ListUserPermissions)" | Out-File UserAccessReport.csv -Append } } #Its a SharePoint Group, So search inside the group and check if the user is member of that group else { foreach($user in $ListRoleAssignment.member.users) { if($user.LoginName -eq $SearchUser) { #Write-Host "$SearchUser is Member of " $ListRoleAssignment.Member.Name "Group" #Get the Group's Permissions on site $ListGroupPermissions=@() foreach ($RoleDefinition in $ListRoleAssignment.RoleDefinitionBindings) { $ListGroupPermissions += $RoleDefinition.Name +";" } #write-host "Group has these permissions: " $ListGroupPermissions #Send the Data to Log file "$($Web.Url) `t Site `t $($List.Title)`t Member of $($ListRoleAssignment.Member.Name) Group `t $($ListGroupPermissions)" | Out-File UserAccessReport.csv -Append } } } } } } } } } #Call the function to Check User Access GetUserAccessReport $siteUrl $userToFind
Wednesday, October 23, 2013

How to Log Errors in SharePoint Hosted Apps?

It is most common thing to log error message if some exception occurs within the code, so that user can find out what causing the error. It is straight forward if you using Server side object model. Since Hosted apps only use JavaScript object model and its bit new to many of us, not sure which namespace/class to use.

 

We use SP.Utilities.Utility.logCustomAppError method to log the app errors. Following is the sample code

 

 

function onFail(sender, args) {

    logAppError(args.get_message() + '\n' + args.get_stackTrace());
}

function logAppError(message) {
    SP.Utilities.Utility.logCustomAppError(context, message);
    this.context.executeQueryAsync();
}

Wednesday, October 16, 2013

SharePoint 2013 App Model – How to View list With in APP

If you working on SharePoint 2013 APP, at some point you defiantly want to see list items contained within the app. Unfortunately there is no navigation to traverse to list.

 

To view specific list in “APP Web”, you directly type the url which specified in the following format in browser

http://<APP WEB URL>/<APP NAME>/Lists/<List Name>/AllItems.aspx

Ex: http://app-0eb6021fad963e.apps.com/sites/SP2K13/WhiteCaseEDARAPP/Lists/Calendar/AllItems.aspx

 

If in case you want to see the List settings,

  • Click “Modify View” under List tab

image

  • Click on “Settings” link as shown below

image

Friday, August 30, 2013

SharePoint 2007 – Custom Alert Template Issue

Recently one of our Business user requested to use “Custom Alerts on old SharePoint” even though we are in the process of upgrading to SharePoint 2013.

 

Anyway I found a nice article to implement “Custom Alert Templates” here. This is what I did, in simple steps.

  • Created a copy of “AlertTemplates.xml” found in 12 hive\Templates\XML
  • Created a new “AlertTemplate” section with in the XML and gave the unique name (simply copy the GeneraicList and renamed the Name)
  • Made couple of changes to Styles and layout (adding new tables to show Company logo)
  • Ran the STSADM command to update the template
  • Create a  small tool in VS to update the template name to specific list
  • Reset the IIS
  • Reset the SharePoint Timer Service

 

Even though I followed same as mentioned in the article, still alert emails are defaulting to the old template no matter what i did (Even I made exact changes to generic list section to see at least its falling into that)

 

After spending couple of days, I removed existing alerts on the list and created new one. Now i see the emails with update template.

I found out that, if we already have alerts setup on the list before updates, even you change the list to use different template (through code), SharePoint still sends alert emails using the template that was assigned to the list at the time of Alert setup.

 

Lesson learned !!!

Tuesday, July 9, 2013

SharePoint 2013 - “We’re having a problem opening this location in File Explorer, Add this web site to your Trusted sites list and try again”

I got the following error, when I try to open the library within file explorer, I received following error message

 

“We’re having a problem opening this location in File Explorer, Add this web site to your Trusted sites list and try again”

image

As it says, i tried to add the current site to Trusted List, but still having the issue to open in file explorer. After goggling a bit, I found that I have to enable the “WebClient” service.

 

Steps

1. Go to Run, type “Services.msc” and press Enter.

2. Select “WebClient” service and start the service, if you already have.

For me it’s not showing, so I have to Install “Desktop Experience” feature. To do that

1. Go to Run, type “Server Manager” and press Enter.

2. Select Features and then select Add Features

image

image

3. Select “Desktop Experience” checkbox and select “Add Required Features” on following popup screen

image

4. Click “Next”

5. Click “Install”

6. Once you restart the computer, start the “WebClient” service.

image

Wednesday, November 14, 2012

Get Public Key Token From Visual Studio

To add a command within Visual Studio

  • Got to Tools and then select External Tools
  • Click Add Button
  • Name it what ever you want, I name it “Get SN Token”
  • on Command text, select following location

    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sn.exe

  • On Arguments, type following

    -Tp $(TargetPath)

image

Monday, May 14, 2012

How to connect Oracle from SQL Server Management Studio

Recently I am working with Oracle database and I want to see the list of tables and views. As we all know its not as friendly as SQL server. So I want to connect (Linked Server) the oracle to SQL SERVER for quick view of the data. Here are the steps I followed to setup a linked server.

  1. Install Oracle Database 10g Client
    • Select the Custom Installation
    • Select the following under available products components
      • Oracle Database utilities
      • SQL * Plus
      • Oracle windows Interfaces
        • Oracle ODBC Driver
        • Oracle Provider for OLEDB
        • Oracle Data Provider for .NET
      • Oracle Net
  2. At the point where we have to do the configuration, enter the following information
    • Service Name (may not be service name, but it is the first box that you type something in) – enter ORADB1 (for example)
    • Then select TCP
    • In the next box enter you Oracle DB server name where you want to connect.
    • Change the port to 1501 (for example)
    • If there is a textbox for Net Service name - it is ORADB1 (for example)
  3. REBOOT
  4. Open SQL Server management Studio and right click on “OraOLEDB.Oracle” under Server Objects –> Linked Servers –> Providers and Select Properties. Here Enable “Allow inprocess”
  5. Right click on Linked Server and select “New Linked Server”. Enter the following
    • Linked Server : A name of your choice
    • Provider : Oracle Provider for OLE DB
    • Product Name : A name of your choice
    • Data Source : This must match the Host you defined in TNSNAMES.ora which you can find in C:\oracle\product\10.2.0\client_2\NETWORK\ADMIN (mine is client_2, yours might be different).
    • Under Security tab, Select “Be made using this security context” and enter user name and password to connect oracle db.

 

Now I can see the Oracle data into SQL Server management studio and able to query if I want to.

SELECT * FROM [LINKED SERVER NAME]..[NAME Appears before Table name].[TABLE NAME]