Quantcast
Channel: SharePoint Diary
Viewing all 1058 articles
Browse latest View live

SharePoint 2013 Design Manager - Cannot Map Network Drive in Windows Server 2008/2012?

$
0
0
Problem: 
I was trying to map Master Page Gallery as network drive from Windows Server 2008 R2, but got this error message:
"Network Error: Windows cannot access <URL>. Check the spelling of the name. Otherwise, there might be a problem with your network. To try to identify and resolve network problems, click Diagnose. Error code: 0x80070043. The network name cannot be found.
sharepoint 2013 map network drive windows cannot access

Solution:
This is due to: "Desktop  Experience" feature not enabled on Windows Servers by default. To resolve this error, follow these steps:
  • Open Server Manager in Windows Server 
  • Click on "Features" node and then Click on "Add Feature" link.
  • Select "Desktop Experience" and click Next >> Next >>Install to complete the wizard.
    sharepoint design manager map network drive cannot access
Once rebooted, I was able to map my SharePoint 2013 master pages gallery to network drive successfully!

Open with Explorer: Network Error - Windows cannot access URL@SSL\DavWWWRoot\SiteURL

$
0
0
Problem: 
Openwith Explorer button in SharePoint 2010 site gave this error message on a particular document library.
Network Error - Windows cannot access URL@SSL\DavWWWRoot\SiteURL\Library  You do not have permission to access \\web-app-url@com@SSL\DavWWWRoot\Library-URL. Contact your network administrator to request access.
Network Error - Windows cannot access URL@SSL\DavWWWRoot\SiteURL\Library
You do not have permission to access \\web-app-url@com@SSL\DavWWWRoot\Library-URL. Contact your network administrator to request access.

Observation: 
  • Issue is happening only with a particular library. Explorer view works fine with all other document libraries in the same environment. Issue is not specific to a particular client machine or user.
  • Open with explorer from the Root level of the library and got the above error. Tried going into each sub-folders and clicking on "Open with Explorer" worked fine, Except for one folder where SharePoint prompted for credentials three times and gave "Your client does not support opening this list with Windows Explorer." - So that's the culprit.
Solution:
Tried running Windows update, Various hot fixes from Microsoft KB's.. But finally, renamed the problematic folder by manually typing the same name and it worked!

SharePoint People Search Results gives "Domain\Account" Instead of User Display Name

$
0
0
Problem:
SharePoint 2010 people search gives "Domain\AccountID" instead of Display name of the user!


Solution:
SharePoint uses "Preferred Name" property which is mapped with "Display Name" property from AD in People search results. Here, I found the root cause of the problem as: User profile not in sync!

Steps to resolve:
  • Make sure in AD, display name field is set properly
  • Go to SharePoint central Administration >> Do a full profile import. 
  • Once you run full profile import, You should see the display name field updated  in user profiles.
  • Run SharePoint search incremental crawl once for the search results to get updated.




Get and Export User Profile Properties using PowerShell in SharePoint 2013

$
0
0
Its a common requirement in SharePoint to prepare reports from user profile properties. Here is my PowerShell scripts to get user profile properties in SharePoint.
Important: Make sure User Profile Service Application is created , up and running before running these scripts! and run as Farm Administrator!!

Get user profile Properties in SharePoint 2013 using PowerShell
#Configuration Variables
$SiteURL = "http://mysite.crescent.com"
$UserLogin="Crescent\Salaudeen"

#Get Objects
$ServiceContext = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserLogin)

#Retrieve User Profile Properties
Write-host $UserProfile["PreferredName"]
Write-host $UserProfile["WorkEmail"]

You are not limited to these fields, But there are plenty of more fields in User Profiles. To get all available user profile properties, use:
$UserProfile.Properties | Select DisplayName, Name

PowerShell to Query & Export user profile properties of all users in SharePoint:
Lets use PowerShell to get and export user profile properties of all users.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://portal.crescent.com"
$outputReport = "c:\user_profiles.csv"

#Get Objects
$ServiceContext = Get-SPServiceContext -site $SiteURL
$UPM = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get All User Profiles
$UserProfiles = $UPM.GetEnumerator()
Write-host "Total Number of User Profiles found:"$UserProfiles.Count

#Array to hold Profiles
$ProfileDataCollection = @()

#Iterate through each profile
foreach ($Profile in $UserProfiles)
{
$ProfileData = New-Object PSObject
#Retrieve User profile Properties
$ProfileData | Add-Member -MemberType NoteProperty -name "Account" -value $Profile["AccountName"]
$ProfileData | Add-Member -MemberType NoteProperty -name "Display Name" -value $Profile["PreferredName"]
$ProfileData | Add-Member -MemberType NoteProperty -name "E-Mail" -value $Profile["WorkEmail"]
$ProfileData | Add-Member -MemberType NoteProperty -name "Manager" -value $Profile["Manager"]
$ProfileData | Add-Member -MemberType NoteProperty -name "Department" -value $Profile["Department"]

#Add to Array
$ProfileDataCollection+=$ProfileData
write-host "Processed Profile:"$profile["PreferredName"]
}
#Export User Profile data to CSV
$ProfileDataCollection | Export-Csv $outputReport –NoType

This script exports given user profile properties of all users as CSV file:
get user profile powershell sharepoint 2013

Disable Redirect from User Information Page (userdisp.aspx) to MySite Profile Page (Person.aspx)

$
0
0
If you want to quickly check SharePoint user profile properties, You can get it from user information list or by simply clicking on user name hyperlinks from metadata fields such as: Created by. Usually, user profile page points to:
  • http://sharepointsite.com/_layouts/userdisp.aspx?ID=123
When clicked on user name hyperlink, will get redirected to My Site profile page (E.g. http://mysite/person.aspx?accountname) if the user has a my site profile created.

If the user has My site profile created, then the UserDisp.aspx page redirects to his/her My site profile page automatically.

Is there any way to get the basic version of userdisp.aspx, instead of redirecting them to the MySite profile of that person when someone clicks on such links? Well, Here is a nifty trick to stop redirecting to user's Mysite profile page and get the simple User Information.
  • Add:Force=True parameter to the above URL. So, it will be:
    http://portal.ad2012.loc/_layouts/userdisp.aspx?Force=True&ID=20
What if You want to avoid profile redirect permanently?
Behind the scenes, there is a OOTB user control called "MySiteRedirection.ascx" User control tied to a delegate control "DelctlProfileRedirection" on userdisp.aspx page that does this re-direction. You can either replace this delegate control or you can simply disable the feature: "MySite" To avoid profile redirect.

SharePoint Site Collection Permission Report using PowerShell

$
0
0
Another PowerShell report generating requirement: SharePoint Site Collection Permission Report to audit permissions on each and every object under a site collection.

This PowerShell script generates a report in HTML format, which consists of
  • Permission setup on All subsites under a site collection
  • Site collection administrators list
  • Permissions applied on each SharePoint object - Such as web (subsite), List, Folder and List Item.
  • Permissions configured for Users, SharePoint Group and AD Groups
  • SharePoint Groups and members of each group who has access.
How to run this script?
How to run the script? Well, Just copy-paste the given script below to either PowerShell ISE or notepad, save it something like "PermissionRpt.ps1", change the configuration variables such as "Site collection URL, Output Report, etc. accordingly. Save and Hit F5!
sharepoint permissions report

SharePoint 2013/2010 permissions report PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$HTMLTemplate=@"
<html>
<head>
<!-- Sal - Javascript Function to apply formatting -->
<script type="text/javascript">
function altRows(id){
if(document.getElementsByTagName){
var table = document.getElementById(id);
var rows = table.getElementsByTagName("tr");
for(i = 0; i < rows.length; i++){
if(i % 2 == 0){
rows[i].className = "evenrowcolor";
}else{
rows[i].className = "oddrowcolor";
}
}
}
}
window.onload=function(){
altRows('alternatecolor');
}
</script>

<!-- CSS Styles for Table TH, TR and TD -->
<style type="text/css">
body{ font-family: Calibri; height: 12pt; }

table.altrowstable {
border-collapse: collapse; font-family: verdana,arial,sans-serif;
font-size:11px; color:#333333; border-width: 1px; border-color: #a9c6c9;
border: b1a0c7 0.5pt solid; /*Sal Table format */
}
table.altrowstable th {
border-width: 1px; padding: 5px; background-color:#8064a2;
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt;
color: white; font-size: 11pt; font-weight: 700; text-decoration: none;
}
table.altrowstable td {
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black;
font-size: 11pt; font-weight: 400; text-decoration: none;
}
.oddrowcolor{ background-color: #e4dfec; }
.evenrowcolor{ background-color:#FFFFFF; }
</style>
</head>
<body>
"@

#Function to get permissions of an object Sal. Such as: Web, List, Folder, ListItem
Function Get-Permissions([Microsoft.SharePoint.SPRoleAssignmentCollection]$RoleAssignmentsCollection, $OutputReport)
{
foreach($RoleAssignment in $RoleAssignmentsCollection)
{
#Get the Permissions assigned to Group/User
$UserPermissions=@()
foreach ($RoleDefinition in $RoleAssignment.RoleDefinitionBindings)
{
#Exclude "Limited Access" - We don't need it sal.
if($RoleDefinition.Name -ne "Limited Access")
{
$UserPermissions += $RoleDefinition.Name +";"
}
}

if($UserPermissions)
{
#*** Get User/Group Name *****#
$UserGroupName=$RoleAssignment.Member.Name
$UserName=$RoleAssignment.Member.LoginName
#**** Get User/Group Type ***** Is it a User or Group (SharePoint/AD)?
#Is it a AD Domain Group?
If($RoleAssignment.Member.IsDomainGroup)
{
$Type="Domain Group"
}
#Is it a SharePoint Group?
Elseif($RoleAssignment.Member.GetType() -eq [Microsoft.SharePoint.SPGroup])
{
$Type="SharePoint Group"
}
#it a SharePoint User Account
else
{
$Type="User"
}
#Send the Data to Report
" <tr> <td> $($UserGroupName) </td><td> $($Type) </td><td> $($UserName) </td><td> $($UserPermissions)</td></tr>" >> $OutputReport
}
}
}

Function Generate-PermissionRpt()
{
Param([Parameter(Mandatory=$true)] [string]$SiteCollectionURL,
[Parameter(Mandatory=$true)] [string]$OutputReport,
[Parameter(Mandatory=$true)] [bool]$ScanFolders,
[Parameter(Mandatory=$true)] [bool]$ScanItemLevel)

#Try to Get the site collection
try
{
$Site = Get-SPSite $SiteCollectionURL -ErrorAction SilentlyContinue
}
catch
{
write-host Site Collection with URL:$SiteCollectionURL Does not Exists!
return
}

#Append the HTML File with CSS into the Output report
$Content = $HTMLTemplate > $OutputReport

"<h2> Site Collection Permission Report: $($Site.RootWeb.Title) </h2>" >> $OutputReport

#Table of Contents
"<h3> List of Sites</h3> <table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr><th>Site Name </th><th> URL </th><th> Permission Setup </th></tr>" >> $OutputReport
#Get Users of All Webs : Loop throuh all Sub Sites
foreach($Web in $Site.AllWebs)
{

if($Web.HasUniqueRoleAssignments -eq $true)
{
$PermissionSetup ="Unique Permissions"
}
else
{
$PermissionSetup="Inheriting from Parent"
}

"<tr> <td> <a href='#$($web.Title.ToLower())'>$($web.Title)</a> </td><td> $($web.URL)</td> <td> $($PermissionSetup)</td></tr>" >> $OutputReport
}

#Site Collection Administrators Heading
"</table><br/><b>Site Collection Administrators</b>" >> $OutputReport
"<table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> $OutputReport

#Write Table Header
"<th>User Account ID </th> <th>User Name </th></tr>" >> $OutputReport

#Get All Site Collection Administrators
$Site.RootWeb.SiteAdministrators | sort $_.Name | ForEach-Object {
"<tr><td> $($_.LoginName) </td> <td> $($_.Name)</td></tr> " >> $OutputReport
}

$Counter=0;
#Get Users of All Webs : Loop throuh all Sub Sites
foreach($Web in $Site.AllWebs)
{
Write-Progress -Activity "Collecting permissions data. Please wait..." -status "Processing Web: $($Web.URL)" -percentComplete ($Counter/$Site.AllWebs.count*100)

#Check if site is using Unique Permissions or Inheriting from its Parent Site!
if($Web.HasUniqueRoleAssignments -eq $true)
{
"</table><br/><hr> <h3>Site: <a name='$($Web.Title.ToLower())' href='$($web.URL)' target='_blank'>$($Web.Title)</a> is using Unique Permissions. </h3>" >> $OutputReport
}
else
{
"</table><br/><hr> <h3>Site: <a name='$($Web.Title.ToLower())' href='$($web.URL)' target='_blank'>$($Web.Title)</a> is Inheriting Permissions from its Parent Site.</h3>" >> $OutputReport
}

#Get the Users & Groups from site which has unique permissions - TOP sites always with Unique Permissions
if($Web.HasUniqueRoleAssignments -eq $True)
{
Write-host Processing Web $Web.URL
#*** Get all the users granted permissions DIRECTLY to the site ***
"<b>Site Permissions</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> $OutputReport
"<th>Users/Groups </th> <th> Type </th><th> User Name </th> <th>Permissions</th></tr>" >> $OutputReport

#Call the function to get Permissions Applied
Get-Permissions $Web.RoleAssignments $OutputReport


#****** Get Members of Each Group at Web Level *********#
"</table></br> " >>$OutputReport

#Check if any SharePoint Groups Exists, if yes, Get members of it
$WebGroupRoleAssignments = $Web.RoleAssignments | Where { $_.Member.GetType() -eq [Microsoft.SharePoint.SPGroup]}
if($WebGroupRoleAssignments)
{
"<b>Group Users</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >>$OutputReport
foreach($WebRoleAssignment in $WebGroupRoleAssignments)
{
"<th colspan='3'><b>Group:</b> $($WebRoleAssignment.Member.Name)</th></tr> " >> $OutputReport
foreach($user in $WebRoleAssignment.member.users)
{
#Send the Data to Log file
" <tr> <td> $($user.Name) </td><td> $($user.LoginName) </td><td> $($user.Email)</td><tr>" >> $OutputReport
}
}
}
} #Web.HasUniqueRoleAssignments Over

#******** Check All List's Permissions ********/
foreach($List in $Web.lists)
{
#Skip the Hidden Lists
if( ($List.HasUniqueRoleAssignments -eq $True) -and ($List.Hidden -eq $false))
{
"</table><br/><b>List: [ $($List.Title) ] at <a href='$($List.ParentWeb.Url)/$($List.RootFolder.Url)'>$($List.ParentWeb.Url)/$($List.RootFolder.Url)</a> is using Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> $OutputReport
"<th>Users/Groups </th><th> Type </th><th> User Name </th><th> Permissions</th></tr>" >> $OutputReport

#Call the function to get Permissions Applied
Get-Permissions $List.RoleAssignments $OutputReport
}
"</table>" >>$OutputReport

#******** Check Folders with Unique Permissions ********/
if($ScanFolders -eq $True)
{
$UniqueFolders = $List.Folders | where { $_.HasUniqueRoleAssignments -eq $True }
#Check if any folder has Unique Permission
if($UniqueFolders)
{
#Get Folder permissions
foreach($folder in $UniqueFolders)
{
#Write Table Headers
$FolderURL=$folder.ParentList.ParentWeb.URL/$folder.Url
"<br/><b>Folder: <a href='$($FolderURL)' target='_blank'>$($Folder.Title)</a> is using Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> $OutputReport
"<th>Users/Groups </th><th> Type </th><th> User Name </th><th> Permissions</th></tr>" >> $OutputReport

#Call the function to get Permissions Applied
Get-Permissions $folder.RoleAssignments $OutputReport

"</table>" >>$OutputReport
}
}
}

#******** Check Items with Unique Permissions ********/
if($ScanItemLevel -eq $True)
{
$UniqueItems = $List.Items | where { $_.HasUniqueRoleAssignments -eq $True }
#Check if any Item has Unique Permission Sal
if($UniqueItems)
{
#Get Folder permissions
foreach($Item in $UniqueItems)
{
#Get Item's Name if Title is NULL
if($Item.Title -ne $null) {$ItemTitle = $Item.Title } else {$ItemTitle= $Item["Name"] }
#Write Table Headers
$ItemURL= $item.ParentList.ParentWeb.Site.MakeFullUrl($item.ParentList.DefaultDisplayFormUrl)
"<br/><b>Item: <a target='_blank' href='$($ItemURL)?ID=$($Item.ID)'>$($ItemTitle)</a> in list/library <a href='$($List.ParentWeb.Url)/$($List.RootFolder.Url)'>$($List.Title) </a> is using Unique Permissions.</b><table class='altrowstable' id='alternatecolor' cellpadding='5px'><tr>" >> $OutputReport
"<th>Users/Groups </th><th> Type </th><th> User Name </th><th> Permissions</th></tr>" >> $OutputReport

#Call the function to get Permissions Applied
Get-Permissions $Item.RoleAssignments $OutputReport

"</table>" >>$OutputReport
}
}
}
} #List
$Counter=$Counter+1;
} #Web
"</body></html>" >>$OutputReport
Write-host "`n Permission report generated successfully at "$OutputReport

}

#**********Configuration Variables************
$OutputReport = "C:\PermissionRpt.htm"
$SiteCollURL="http://portal.crescent.com"
$ScanFolders=$False
$ScanItemLevel=$False

#Call the function to Get Permissions Report
Generate-PermissionRpt $SiteCollURL $OutputReport $ScanFolders $ScanItemLevel

Output:
Script is included with a progress bar indicator. Once execution completed, it generates a HTM file at given location.
You can optionally turn on Folders & Item Level flags to include them in permission reporting. If so, You can expect some delays in script execution!

Here is a sample site collection permission report this script generated! 
sharepoint site collection permission report
This script doesn't count "Limited Permissions"!

Query-Import SharePoint List to Excel using Data Source Connections

$
0
0
Have you ever had to query and import SharePoint list to Excel? or ever required to use SharePoint list as excel data source? Well, just follow these steps to excel data connection to use SharePoint list as excel data source:

Step 1: Create a SharePoint list view with desired columns and order:
Go to your SharePoint list, Create a new view matching your requirement by adding necessary columns to it.

Step 2: Use Export to Excel to generate Data Source Connection
Navigate to your SharePoint list view created in Step-1, Use "Export to Excel" button under "List" tab. This imports SharePoint list to Excel and establishes data source connection in Excel as below.
use sharepoint list as excel datasource
 Make sure you set the below properties to skip column width and preserve sort/filter/layout/formats.
excel data connection to sharepoint list
You can also set the data refresh when opening the file.
sharepoint list as excel data source

How to Refresh the Data?
All you have to do is, either right click on any data imported and click "Refresh" in the context menu or Click on "Refresh All" button under "Data" tab of Excel.

Once you click refresh, Your Excel sheet will be synced from SharePoint list (One way - from SharePoint list!)
query sharepoint list using excel
Fix data format in Lookup and People picker columns
When you import data from SharePoint list to Excel, It just imports the data in the same format SharePoint stores internally. Say for E.g. You'll see John Mathew;#157;#Omar Saad in people picker column.

Solution:
Lets create a custom function in VBA code to replace the format "Number#;" in People Picker, Lookup columns with regular expressions:
  • Go to Excel >> File >> Options >> Customize Ribbon >> Enable "Developer" check box under Customize the Ribbon. This adds a new tab "Developer" in the Ribbon. 
  • Click on "View Code" button under "Controls" group of Developer Tab. 
  • Click on Tools >> Add Reference >> Pick "" to add Regular Expressions library: Microsoft VBScript Regular Expressions 5.5
  • Right Click the VBAProject >> Insert >> Module. Insert the below code into the Module.
    Function xREPLACE(pattern As String, searchText As String, replacementText As String, Optional ignoreCase As Boolean = True) As String
    On Error Resume Next
    Dim RegEx As New RegExp
    RegEx.Global = True
    RegEx.MultiLine = True
    RegEx.pattern = pattern
    RegEx.ignoreCase = ignoreCase
    xREPLACE = RegEx.Replace(searchText, replacementText)
    End Function
  • Now, Create a new column in Excel, Say for E.g. You are going to properly format "Deal Lead" column, Enter the formula as:
    =xREPLACE("\#\d*;|#\d*|\d*;#",TRIM([Deal lead])," ")
  • You can hide the original column "Deal Lead" and Name your new columns similar to "Deal Lead", say "Deal leader" or add a . (dot) prefix.
  • Save the Excel file as "XLSM" format so that the code saved along with your Excel sheet.

Server Error in '/x' Application - Excel Web App Error Solution

$
0
0
Problem:
All of a sudden Office Web Apps Excel Web App stopped working and gave this Runtime error message on opening Microsoft Excel files from SharePoint 2013:
Server Error in '/x' Application.
SharePoint Office Web Apps Server Error in '/x' Application

Solution: 
This occurs due to the public key which connects to the WOPI application such as Office Web Apps Server to the SharePoint farm goes out of sync! To resolve the issue, Run from any SharePoint Server:  
Update-SPWOPIProofKey

How to Delete a Service Application in SharePoint 2013 using PowerShell

$
0
0
Requirement: Delete SharePoint 2010/2013 Service Application using PowerShell.

How to Delete a Service Application in SharePoint 2013:
  • Go to SharePoint 2013 Central Administration site 
  • Navigate to Application Management >> Manage service applications
  • In the Manage Service Applications page, Select the Service application that you want to delete.
  • click Delete button from the Ribbon.
     how to delete service application in powershell sharepoint 2013
  • You'll get a confirmation dialog, select "Delete data associated with the Service Applications" if you want to delete the service application database. leave this check box if you don't want to delete the Service application's database.
  • Click OK to delete the service application. Once deleted, you'll get the confirmation dialog.
     sharepoint 2010 delete service application powershell force
Delete a Service Application in SharePoint 2013 using PowerShell
At times you may have to use PowerShell in scenarios such as you are unable to delete a Service application as it may corrupted.To get rid of a Service Application and remove it completely using PowerShell? Well, Here are the PowerShell cmdlets to Help you!

To remove a service application from PowerShell, use Remove-SPServiceApplication cmdlet.
Syntax: 
Remove-SPServiceApplication {Service-App-ID} [-RemoveData]
E.g.
Remove-SPServiceApplication "222b3f48-746e-4cd2-a21c-018527554120" -RemoveData

Remove-SPServiceApplication needs the GUID of the target service application we want to delete, isn't it? So, How to get the Service Application ID? Here is how:

Run: Get-SPServiceApplication cmdlet, It gets you the below result with ID field:

delete service application using powershell sharepoint 2010

PowerShell Script to Delete a SharePoint 2013 Service Application:
Lets force delete a service application using its display name with PowerShell.
#Display Name 
$DisplayName="Excel Services Application"

#Get the Service Application from its Display Name
$SeviceApp = Get-SPServiceApplication -name $DisplayName

#Delete the Service Application
Remove-SPServiceApplication $SeviceApp -removedata -confirm:$false

Get Service Application from Its type name and remove:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Type Name String
$TypeName="Usage and Health Data Collection Service Application"

#Get the Service Application from its Type
$SeviceApp = Get-SPServiceApplication | Where {$_.TypeName -eq $TypeName}

#Delete the Service Application
Remove-SPServiceApplication $SeviceApp -removedata -confirm:$false

Here is the Type Name of all service Applications:
Type
Access Services Web Service Application
Access Services 2010 Web Service Application
App Management Service Application
Application Discovery and Load Balancer Service Application
Business Data Connectivity Service Application
Excel Services Application Web Service Application
Machine Translation Service
Managed Metadata Service
PerformancePoint Service Application
PowerPoint Conversion Service Application
Search Administration Web Service Application
Search Service Application
Secure Store Service Application
Security Token Service Application
State Service
Usage and Health Data Collection Service Application
User Profile Service Application
Visio Graphics Service Application
Work Management Service Application
Word Automation Services
All above cmdlets removes service application and its proxy!

How to delete a service application proxy: 
If you want to delete the service application proxy alone, use: Remove-SPServiceApplicationProxy cmdlet:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Type Name String
$TypeName="Machine Translation Service Proxy"

#Get the Service Application Proxy from its Type
$SeviceAppProxy = Get-SPServiceApplicationProxy | Where {$_.TypeName -eq $TypeName}

#Remove the Service Application Proxy
Remove-SPServiceApplicationProxy $SeviceAppProxy -removedata -confirm:$false

Get/Set Hyperlink Field Values in SharePoint using PowerShell

$
0
0
Here is my PowerShell scripts to get and set hyperlink column values:

Get Hyperlink Field Value using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://intranet.crescent.com/"
$ListName = "UserProfiles"
$FieldName="Picture"

#Get the Web, List Objects
$web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)

If($list)
{
foreach($Item in $List.Items)
{
#Get the Hyperlink column
$Picture = New-Object Microsoft.SharePoint.SPFieldUrlValue($Item[$FieldName])
#Get the URL of the Hyperlink
$Picture.URL
#Get the Decription - Title
$Picture.Description
}
}
Update Hyperlink Field value using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://intranet.crescent.com/"
$ListName = "UserProfiles"
$FieldName="Picture"

#Get the Web, List Objects
$web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)

If($list)
{
#Prepare the Hyperlink column
$Picture = New-Object Microsoft.SharePoint.SPFieldURLValue
$Picture.Description = "Profile Picture"
$Picture.URL = "http://intranet.crescent.com/UserProfiles/Images/profile.jpg"

#Add new List Item
$Item = $List.AddItem()
$Item[$FieldName] = $Picture
$Item.Update()

Write-host "New Item Added Successfully!"
}

Update User Profile Properties in SharePoint using PowerShell

$
0
0
SharePoint User Profile properties are usually imported from Active Directory to provide information about SharePoint users. At times, we may have to update SharePoint user profiles manually. My scenario is to update user profile pictures from a SharePoint library. Here is my PowerShell script:

PowerShell Script to update User Profile Property:
#Configuration Variables
$MySiteURL = "https://Mysite.Crescent.com"
$UserLogin="Crescent\Salaudeen"

#Get User Profile Objects
$ServiceContext = Get-SPServiceContext -site $MySiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Check if user Exists
if ($UserProfileManager.UserExists($UserLogin))
{
#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserLogin)

#Update user profile picture Property
$userProfile["PictureURL"].Value = "https://intranet.Crescent.com/UserProfileImages/Salaudeen.jpg"
$userProfile.Commit()
write-host "User Picture Updated Successfully!" -f Green
}
else
{
write-host "$($UserLogin) Not Found!" -f Red
}
Make sure there to remove mapping between SharePoint user profile property and Active Directory under User profile service application's "Manage User Properties" page. If there is a mapping defined, when next time user profile sync runs, your updates will be overwritten!
sharepoint 2010 update user profile properties powershell

Once updated, Run incremental/full search crawl for the updates to reflect in SharePoint search!

Fix "The site is not valid. The 'Pages' document library is missing" Error

$
0
0
Problem: After trying to deactivate and activate the publishing feature in a site, users started receiving this error: "The site is not valid. The 'Pages' document library is missing". It also happened after importing a subsite backup! Additionally, when tried creating a Publishing Pages they got this error:

The site is not valid. The 'Pages' document library is missing.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.Publishing.InvalidPublishingWebException: The site is not valid. The 'Pages' document library is missing.

Fix "The site is not valid. The 'Pages' document library is missing" Error
Root Cause: SharePoint Publishing feature stores the ID of the "Pages" library in the "__PagesListId" property  of SPWeb property bag. If this property doesn't match with the current "Pages" library, then we get this error! Made sure publishing feature is active and tried de-activate and activate the publishing feature once again.Didn't help.

Solution:
To fix this error, We'll have to set the "__PagesListId" property on the affected web's property bag!

PowerShell Script to Update the Pages List ID:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL="http://SharePoint-Site-URL"

$Web = Get-SPWeb $WebURL
$PagesListID = $web.Lists["Pages"].ID
$Web.AllProperties["__PagesListId"] = $PagesListID.ToString()
$Web.Update()

This PowerShell script to updates the property and corrects the problem.

Update Property Bag Settings using SharePoint designer:
You can also use SharePoint Designer to fix this problem. Here is how:
  • Get your "Pages" library's ID first! Here is How to get SharePoint list GUID
  • Open the SharePoint site which has this issue in SharePoint Designer
  • Select the site object in the tree view and Click on "Site Options" button from the ribbon
  • Check if the property "__PagesListId" exists, If so, update its value to current Pages library ID.
  • If the Property doesn't exists, Click on Add button to add the property. Enter "__PagesListId" as property name and value as the "Pages" Library GUID
  • Save your changes.
That's all!

Create My Site for All Users in SharePoint using PowerShell

$
0
0
SharePoint My Sites are automatically created when the first time Users click on the My Content link. However, To promote the usage of SharePoint social, we deiced to pre-create SharePoint My sites for all users.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Create-MySite($MySiteHost, $UserAccount)
{
#Get Objects
$ServiceContext = Get-SPServiceContext -site $MySiteHost
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Check if user Exists
if ($UserProfileManager.UserExists($UserAccount))
{
#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserAccount)

#Check if User's My site is Cretaed already
if($UserProfile.PersonalSite -eq $Null)
{
$UserProfile.CreatePersonalSite()
write-host "My Site Created Successfully for the User!" -f Green
}
}
else
{
write-host "$($UserAccount) Not Found!" -f Red
}
}

Create-MySite "https://mysite.crescent.com" "Crescent\Salaudeen"

SharePoint: Create Mysite for all users using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$MySiteHost = "https://mysite.crescent.com"

#Get Objects
$ServiceContext = Get-SPServiceContext -site $MySiteHost
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get All User Profiles
$UserProfiles = $UserProfileManager.GetEnumerator()

#Iterate through each profile
foreach ($Profile in $UserProfiles)
{
if($Profile.PersonalSite -eq $Null)
{
#Check if User's My site is Cretaed already
if($Profile.PersonalSite -eq $Null)
{
#$UserProfile.CreatePersonalSite()
write-host "My Site Created Successfully for the User:" $Profile["AccountName"] -f Green
}
else
{
write-host "My Site Already Exists for the User:" $Profile["AccountName"] -f Red
}
}
}
BTW, I've tested this script in SharePoint 2013 to create mysite for all users!

Add Attachment to List Item in SharePoint using PowerShell

$
0
0
PowerShell script to add attachment to list item programmatically in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Add attachment to SharePoint List Item
Function Add-Attachment($Item, $AttachmentPath)
{
$FileContent = [System.IO.File]::ReadAllBytes($AttachmentPath)
$Item.Attachments.Add([System.IO.Path]::GetFileName($AttachmentPath), $FileContent)
$Item.Update()

Write-host "Attachment Added to List Item Successfully!"
}

#Variables
$SiteURL="https://portal.crescent.com/sites/Deals"
$ListName="Tasks"
$ItemID=1
$AttachmentPath="c:\Scripts\ASI-LOG.docx"

$web = Get-SPWeb $SiteURL
$List = $web.Lists[$ListName]
$Item = $list.GetItemById($ItemID)

#Call the function to Add Attachment
Add-Attachment $Item $AttachmentPath

Copy Files Between Document Libraries in SharePoint using PowerShell

$
0
0
Here is my PowerShell script to copy files between SharePoint document libraries:

PowerShell Script to Copy a File from One Library to Another:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for Processing
$WebURL="https://portal.crescent.com/sites/Sales/"
$SourceFile="https://portal.crescent.com/sites/Sales/TeamDocs/InvoiceTemp.xlsx"
$TargetLibrary="Invoice Documents"

#Get Objects
$Web = Get-SPWeb $WebURL
$SourceFile = $Web.GetFile($SourceFile)
$TargetLibrary = $Web.GetFolder($TargetLibrary)

#Copy the file into the Target library
$File = $TargetLibrary.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(), $true)

#Copy Meta-Data
$Item = $File.Item
$item["Created"] = $SourceFile.TimeCreated.ToLocalTime()
$item["Modified"] = $SourceFile.TimeLastModified.ToLocalTime()
$item["Author"] = $SourceFile.Author
$item["Editor"] = $SourceFile.ModifiedBy
#Update
$Item.UpdateOverwriteVersion()

PowerShell Script to Copy All Files Between Document Libraries:
Lets copy all files and folder from one library to another along with their meta-data (Excluding: the above!)
sAdd-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Copy Files from Source Folder to Target
Function Copy-Files($SourceFolder, $TargetFolder)
{
write-host "Copying Files from:$($SourceFolder.URL) to $($TargetFolder.URL)"
#Get Each File from the Source
$SourceFilesColl = $SourceFolder.Files

#Iterate through each item from the source
Foreach($SourceFile in $SourceFilesColl)
{
#Copy File from the Source
$NewFile = $TargetFolder.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(),$True)

#Copy Meta-Data from Source
Foreach($Field in $SourceFile.Item.Fields)
{
If(!$Field.ReadOnlyField)
{
if($NewFile.Item.Fields.ContainsField($Field.InternalName))
{
$NewFile.Item[$Field.InternalName] = $SourceFile.Item[$Field.InternalName]
}
}
}
#Update
$NewFile.Item.UpdateOverwriteVersion()

Write-host "Copied File:"$SourceFile.Name
}

#Process SubFolders
Foreach($SubFolder in $SourceFolder.SubFolders)
{
if($SubFolder.Name -ne "Forms")
{
#Check if Sub-Folder exists in the Target Library!
$NewTargetFolder = $TargetFolder.ParentWeb.GetFolder($SubFolder.Name)

if ($NewTargetFolder.Exists -eq $false)
{
#Create a Folder
$NewTargetFolder = $TargetFolder.SubFolders.Add($SubFolder.Name)
}
#Call the function recursively
Copy-Files $SubFolder $NewTargetFolder
}
}
}

#Variables for Processing
$WebURL="http://portal.crescent.com/sites/sales/"
$SourceLibrary ="Team Docs"
$TargetLibrary = "Sales Documents"

#Get Objects
$Web = Get-SPWeb $WebURL
$SourceFolder = $Web.GetFolder($SourceLibrary)
$TargetFolder = $Web.GetFolder($TargetLibrary)

#Call the Function to Copy All Files
Copy-Files $SourceFolder $TargetFolder

Copy Documents between Sites, Site Collections, Web Applications:
How about copying between Sites? Well, just change the below lines in the script.
#Variables for Processing
$SourceWeb = "http://Your-Source-Web-URL"
$TargetWeb = "http://Your-Target-Web-URL"

$SourceLibrary ="Team Docs"
$TargetLibrary = "Shared Documents"

$SourceFolder = $Source.GetFolder($SourceLibrary)
$TargetFolder = $TargetWeb.GetFolder($TargetLibrary)

#Call the Function to Copy All Files
Copy-Files $SourceFolder $TargetFolder

SharePoint Online: Import CSV File into SharePoint List using PowerShell-CSOM

$
0
0
Scenario: My requirement is to import data from CSV file to SharePoint online list from a local drive, every day!
import CSV data into SharePoint Online List - PowerShell Script

PowerShell Script to import SharePoint List Items from CSV File:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/POC/"
$ListName="Contacts"
$ImportFile ="c:\Scripts\EmpData.csv"
$UserName="Salaudeen@crescent.com"
$Password ="Password goes here"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials

#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)

#Get the Data from CSV and Add to SharePoint List
$data = Import-Csv $ImportFile
Foreach ($row in $data) {

#add item to List
$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$Item = $List.AddItem($ListItemInfo)
$Item["FirstName"] = $row.FirstName
$Item["LastName"] = $row.LastName
$Item["Department"] = $row.Department
$Item["Mobile"] = $row.Mobile
$Item.Update()
$Context.ExecuteQuery()

}
Write-host "CSV data Imported to SharePoint List Successfully!"

PowerShell Error: Add-Type: Could not load file or assembly 'file:///C:\Program Files\Common Files\Micros oft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

$
0
0
Problem: 
When trying to write a client side PowerShell script for SharePoint online, got an error:

Error: Add-Type : Could not load file or assembly 'file:///C:\Program Files\Common Files\Micros
oft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll' or one of its  dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
Add-Type: Could not load file or assembly
Verified SharePoint Server 2013 Client Components SDK is already installed to use Client side assemblies. (if not,  You can download it from: http://www.microsoft.com/en-us/download/details.aspx?id=35585)

Solution:
You need to have PowerShell 3.0 to use Client side assemblies of SharePoint online. So, download and install "Windows Management Framework 3.0" at https://www.microsoft.com/en-us/download/details.aspx?id=34595

Tips: To get your currently installed PowerShell version, type: $PSVersionTable

SharePoint Online: Export List Items to CSV using PowerShell

$
0
0
Requirement: 
Export SharePoint online list items to CSV file from client side.

PowerShell script to Export SharePoint List Items to CSV from Client Side (CSOM):
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/poc/"
$ListName="Employee"
$ExportFile ="c:\Scripts\ListRpt.csv"
$UserName="Salaudeen@crescent.com"
$Password ="Password goes here"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials

#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)

#Get All List Items
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$ListItems = $List.GetItems($Query)
$context.Load($ListItems)
$context.ExecuteQuery()

#Array to Hold List Items
$ListItemCollection = @()

#Fetch each list item value to export to excel
$ListItems | foreach {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["Department"]

#Add the object with above properties to the Array
$ListItemCollection += $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $ExportFile -NoTypeInformation

Write-host "List data Exported to CSV file successfully!"

Related Posts:

SharePoint 2016 RTM is Released!

$
0
0
So the waiting period is over! SharePoint 2016 is in its RTM now!
sharepoint 2016 RTM download

Download SharePoint 2016 RTM Trial from here: https://www.microsoft.com/en-us/download/details.aspx?id=51493

180 day Trial key: NQGJR-63HC8-XCRQH-MYVCH-3J3QR

What's New: Fast Site Collection Creation, Durable Links, Hybrid Features, MinRoles, Large File support, etc.

What's Lost: No more SharePoint Foundation, No Stand-alone Install Mode (with SQL Express), No FIM, etc.

How to Delete a Master Page in SharePoint using PowerShell

$
0
0
Requirement:
After deploying a new master page as part of new branding, We wanted to delete the old master page from all SharePoint sites. As we've applied the new master page, we don't want our existing custom master page to be appear in the master page gallery and master page selection page.

Solution:
PowerShell script to delete the SharePoint master page.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site URL and Master page Name variables
$WebURL="https://portal.crescent.com/sites/sales/"
$MasterPageName="crescent.master"

#Get Objects
$web = Get-SPWeb $WebURL
$MasterPage = $web.GetFolder("_catalogs/masterpage").Files[$MasterPageName]

#Delete the Master page using PowerShell
$MasterPage.Delete();

write-host "Master page deleted!"
This PowerShell script just deletes given master page from the given web. Loop through each web and delete the master page from all.

Remember, If the master page you are trying to delete is configured as either Default master page or custom master page, You can't delete it! change the master page in your code first and then try deleting it again.

Related post: Change Master Page in SharePoint using PowerShell
Viewing all 1058 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>