Tuesday, July 19, 2016

SharePoint 2013 People Picker Error: Sorry, we're having trouble reaching the server

Problem: While trying to add a new user to SharePoint group, SharePoint 2013 People Picker displayed the error: "Sorry, we’re having trouble reaching the server"
SharePoint 2013 People Picker error "Sorry, we’re having trouble reaching the server"

Troubleshooting:
  • The server may not have enough resources such as Memory to process the function without timing out. Try adding more memory to your SharePoint 2013 web front end server.
  • If "HTTP Activation" feature is not enabled, You may face this issue. Loging to your WFE >> Go to Server Manager >> Add ROles and Features >> Select HTTP Activation and install.
  • Try IIS reset once from all front end servers.
  • Check Alternate Access Mappings settings for the web application.
  • Try deactivating "Limited-access user permission lockdown mode" Feature from site collection features (This worked in one of the external facing site).
  • Make sure the domain account you are using for a SharePoint service account has the necessary permissions to read domain accounts, If you have one-way trust domain - Set the app password (stsadm -o setapppassword -password "Password") and follow the KB to add people picker domain https://support.microsoft.com/en-us/kb/2874332
  • Check if Anonymous Authentication is enabled for your web site in IIS.
  • Try updating "Query timeout" value from 25 to 60! (under: 15\TEMPLATE\LAYOUTS\clientpeoplepicker.js >> SPClientPeoplePicker.UserQueryMaxTimeout)
  • Try extending the web application to new port!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Approval Workflow Missing in SharePoint 2013?

Problem: SharePoint approval workflow not available! This happened after migrating from SharePoint 2013 to SharePoint 2016!
sharepoint 2013 approval workflow missing

Solution: This is due to workflow feature not activated for the site collection. To resolve this issue, Just Activate "Workflows" feature for the site collection. Steps in detail:
  • Login to your the target site collection as Site collection administrator
  • Click on Site settings gear >> Click on "Site collection Features" and click activate button next to "Workflows" Feature.
  • That's it! This brings approval workflows back!and all other out of the box workflows like collect feedback, Collect signatures, etc
sharepoint 2010 approval workflow not available

PowerShell Script to activate Workflows feature for all site collections:
You can use PowerShell to activate workflow feature on all site collections, which resolves approval workflow template missing issue.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Workflow Feature ID
$FeatureID="0af5989a-3aea-4519-8ab0-85d91abe39ff"

#Get all Site collections in the farm
$SiteColl =  Get-SPSite -Limit All 
#$SiteColl = Get-SPWebApplication -Identity "http://intranet.crescent.com" | Get-SPSite -Limit All

#Get the Target Feature to Activate
$FeatureToActivate = Get-SPFeature | Where {$_.ID -eq $FeatureID}
 
#Iterate through each site collection
ForEach($Site in $SiteColl)
{
    #Check if Feature is already activated
    $FeatureActivated = Get-SPFeature -site $Site | Where {$_.ID -eq $FeatureId}
  
    If($FeatureActivated -ne $null)
    {
        Write-Host "Feature is already activated at: "$site.Url -ForegroundColor Yellow
    }
    else
    {
        #Activate the feature
        Enable-SPFeature -Identity $FeatureID -URL $Site.URL -Confirm:$False
        Write-Host "Activated Feature on "$site.Url -ForegroundColor Green
    }
}
Tags: approval workflow missing in sharepoint 2013, approval workflow missing sharepoint online, approval workflow not available sharepoint, sharepoint 2010 approval workflow not available, sharepoint approval workflow missing, sharepoint approval workflow not showing, sharepoint approval workflow template missing

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, July 17, 2016

"Object reference not set to an instance of an object" Error on Creating Site Collection

Problem: On creating a new Site collection in SharePoint 2016, got this error message "Object reference not set to an instance of an object"!

On Checking the ULS logs, it revealed detailed error as:
System.NullReferenceException: Object reference not set to an instance of an object.    at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.FindBestContentDatabaseForSiteCreation(IEnumerable`1 contentDatabases, Guid siteIdToAvoid, Guid webIdToAvoid, SPContentDatabase database, SPContentDatabase databaseTheSiteWillBeDeletedFrom)     at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.FindBestContentDatabaseForSiteCreation(SPSiteCreationParameters siteCreationParameters, Guid siteIdToAvoid, Guid webIdToAvoid, SPContentDatabase database, SPContentDatabase databaseTheSiteWillBeDeletedFrom) 
Object reference not set to an instance of an object - on creating new site collection

Root cause:
This is due to a broken content database associated with the particular web application.

Solution: Remove the invalid content database association by following below steps.
Step 1: Get the Web Application GUID
Use the below PowerShell script to get the ID of the web application in question.
(Get-SPWebApplication "http://intranet.crescent.com/").ID

Step 2:  Query the SharePoint Config database with the web application GUID:
Login to your SQL Server, Open SSMS, Run this select query against the farm's configuration database.
SELECT ID, Name, CAST (properties as xml) AS Result 
FROM [Objects]
WHERE ID = '0da122ac-8d9d-4bc1-aa1f-93df85bced3c'
Click on the "Result" column value and search for "m_Databases" and find the database GUID with "null" value.

Step 3: Delete the broken database link:
Now, delete the broken database link using PowerShell.
$WebApp = Get-SPWebApplication "http://intranet.crescent.com/"

$WebApp.ContentDatabases.delete("26449389-6c7e-4c0b-8a89-3ee35c991b35")
This would give: Exception calling "Delete" with "1" argument(s): "Object reference not set to an instance of an object." But don't worry.

This error also occurs when your database server runs out of disk space!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 15, 2016

How to Change Server MinRole After Installing SharePoint 2016

One of the exciting new feature in SharePoint 2016 is Minrole. It defines server's role in the SharePoint 2016 farm, and makes sure all necessary services are running in that server! SharePoint 2016 comes with below Minroles:
  1. Single Server Farm
  2. Front End
  3. Application
  4. Distributed Cache
  5. Search
  6. Custom
Change MinRole in  SharePoint 2016:
Server roles are selected during the installation of SharePoint 2016 or when you join a server to your farm. Based on the Server role selected, certain services will get activated on selected servers. What if you want to change the server role after SharePoint has been provisioned?  With the introduction of MinRoles in SharePoint 2016, its fairly straightforward to switch server roles between anyone among them:
  • Go to SharePoint 2016 Central Administration >> System Settings 
  • Click on Convert server role in this farm under Servers
How to Change Server Role in SharePoint 2016
Now, It takes you to the "Role conversion" page, where you will see the options for all Minroles. Pick the new role from the dropdown and click Apply,  Your server will be changed to New role!
swith server MinRole after provisioning SharePoint 2016
You can't combine two or more MinRoles in one server. However, You can use the Custom role  to achieve the same! To check roles assigned to servers in the farm, Go to: SharePoint 2016 Central Administration >> System Settings > Manage servers in this farm. This page lists all servers and their roles in the farm.

How to Switch Server MinRole using PowerShell?
To change the server role using PowerShell, use Set-SPServer cmdlet.
Set-SPServer -Identity SERVER1 -Role Application
#Set-SPServer -Identity SERVER2 -Role WebFrontEnd


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, July 10, 2016

Add Alternate Access Mapping in SharePoint using PowerShell

Alternate Access Mappings helps to expose a SharePoint web application into different URLs in scenarios such as publishing, load balancing, reverse proxy, etc. Each web application can have up to five different URLs through alternate access mapping, with "Default" zone as mandatory and other optional zones.

How to Configure Alternate Access Mapping in SharePoint Central Administration?
Follow these steps to set alternate access mapping in SharePoint.
  • Go to the SharePoint 2016 Central Administration Site, Click on System Settings from Left navigation menu.
  • From the "System setting" page, click on "Configure Alternate Access Mappings" link under in the "Farm Management" group.
  • You will be presented with the Alternate Access Mappings page. Select your desired web application to get the AAM settings for the specific web application.
powershell add alternate access mapping
Here, The public URL is the address of the Web Application, where the traffic will be routed to.  Internal URLs are whats entered in the browser and its either transformed/mapped into the Public URL.

To add an alternate access mapping, with the target web application selected, Click on "Edit Public URL's" link >> Enter the appropriate URL for respective zone and hit Save to commit your changes.
sharepoint 2013 alternate access mapping powershell
You can also use PowerShell to manage Alternate Access Mappings in SharePoint.

Add alternate access mapping SharePoint using PowerShell:
To add an entry to SharePoint alternate access mapping using PowerShell, use cmdlet: New-SPAlternateURL. Here is an example:
New-SPAlternateURL –WebApplication "http://intranet.crescent.com" -URL "http://portal.crescent.com" –Zone Internet

Add a binding to the web application in IIS:
But wait, You are not yet done. This is a common miss in SharePoint. Although you add AAM entry, You must also add IIS binding for the web application for initial redirect to IIS site.
powershell set alternate access mapping
You can now access the existing SharePoint web application "http://intranet.crescent.com" using the new URL "http://portal.crescent.com".


PowerShell to remove alternate access mapping:
To remove an existing AAM entry, use the PowerShell cmdlet: Remove-SPAlternateURL, Here is an example:
Get-SPAlternateURL –WebApplication "http://intranet.crescent.com" –Zone "Internet" | Remove-SPAlternateURL

Get SharePoint alternate access mappings using PowerShell:
To read all alternate access mappings for a given web application, use this PowerShell script.
Get-SPAlternateURL -WebApplication "http://intranet.crescent.com" | Format-table -AutoSize
 sharepoint powershell add alternate access mapping
Similarly, to get the AAM settings for a specific zone, say: Internet, use:
Get-SPAlternateURL –WebApplication "http://intranet.crescent.com" –Zone "Internet" 

Tags: powershell add alternate access mapping, add alternate access mapping sharepoint 2010 powershell, create alternate access mapping sharepoint 2010 powershell, sharepoint 2013 alternate access mapping powershell, powershell set alternate access mapping, sharepoint powershell add alternate access mapping

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, July 9, 2016

How to Redirect in SharePoint using Alternate Access Mapping (AAM)

Internal URL in SharePoint Alternate Access Mapping is used to redirect from one URL to another. Say for E.g. If you want to redirect or transform from "http://portal.crescent.com" into "http://intranet.crescent.com" use this feature! So, you enter "http://portal.crescent.com" in the address bar of your browser, and it takes you to "http://intranet.crescent.com"!

How to Add URL Redirection using Alternate Access Mapping?
Here is how to achieve web application redirect using AAM.
  • Go to SharePoint 2016 Central Administration >> Click on "System Settings" >> Configure alternate access mappings
  • Select your web application from the drop down list. Click on "Add Internal URLs" link on the toolbar
    sharepoint redirect site to another site
  • Enter the desired URL and select the zone from the list, and hit save to commit your changes. In my case, I wanted to redirect from "http://portal.crescent.com" to "http://intranet.crescent.com"
    sharepoint iis redirect http to https
PowerShell to Add Internal AAM Entry:
To add an internal alternate access mapping entry, use this PowerShell script.
New-SPAlternateURL –WebApplication "http://intranet.crescent.com" -URL "http://portal.crescent.com" –Zone Default –Internal

Update IIS Binding with the Redirect URL:
Once the SharePoint side entry is added, the next step is to add the binding in IIS. Go to IIS, locate your web application >> Edit Bindings >> Add the URL to the binding.
Sharepoint redirect url
Now, open a new browser instance (or open a browser in private mode to avoid caching), Check the URL redirection in place! This redirect not just works for top level URL, but it works for all internal links as well.
This method of redirect can be used in SharePoint to redirect from HTTP to HTTPS.

How to remove the Redirect?
From the "Alternate Access Mappings" page,  Just click on the redirect URL you had created, and in the Edit Internal URLs page, hit "Delete" button to remove redirection placed for the web application.
sharepoint redirect relative url
Beware of the browser caching: You may not get the changes immediately even you made some modification as above. Try opening a new private browser and check!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Export SharePoint Configuration Inventory to XML using PowerShell

Requirement: We had to compare certain SharePoint inventories between different environment, such as web applications, content databases, etc. So had to extract and export SharePoint configurations into XML file.

PowerShell Script to Export Web Applications List into XML
SharePoint export data to XML

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node
[System.XML.XMLElement]$XMLRoot=$XMLDocument.CreateElement("WebApplications")

#Get all web applications and loop through
$WebApps = Get-SPWebApplication
ForEach($webApp in $WebApps)
{
    $WebAppElement = $XMLDocument.CreateElement("WebApplication")
    $WebAppElement.SetAttribute("Name", $WebApp.DisplayName)
    $WebAppElement.SetAttribute("URL", $WebApp.URL)
    #Append the data to Root node
    $XMLRoot.AppendChild($WebAppElement)
}
# Append Root Node to XML
$XMLDocument.AppendChild($XMLRoot)

#Save File
$XMLDocument.Save("c:\WebApps.xml")

Script output:
sharepoint export data to xml

Inventory Web Applications and Its Content Databases associated to XML
Lets add database information to it:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node "WebApplications"
[System.XML.XMLElement]$WebAppRootElement=$XMLDocument.CreateElement("WebApplications")

#Get all web applications and loop through
$WebApps = Get-SPWebApplication
ForEach($webApp in $WebApps)
{
    $WebAppElement = $XMLDocument.CreateElement("WebApplication")
    $WebAppElement.SetAttribute("Name", $WebApp.DisplayName)
    $WebAppElement.SetAttribute("URL", $WebApp.URL)

    #Append the WebApplication data to "WebApplications" Node
    $WebAppRootElement.AppendChild($WebAppElement)

    #Database Element
    $DatabaseRootElement = $XMLDocument.CreateElement("Databases")

    $ContentDBs = $webApp.ContentDatabases
    ForEach($Database in $ContentDBs)
    {
        $DatabaseElement = $XMLDocument.CreateElement("Database") 
        $DatabaseElement.SetAttribute("Name", $Database.DisplayName)
        $DatabaseElement.SetAttribute("ID", $Database.ID)
           
        #Append the Database elements to "WebApplication" node
        $WebAppElement.AppendChild($DatabaseElement)
    }
}
# Append Root Node to XML
$XMLDocument.AppendChild($WebAppRootElement)

#Save File
$XMLDocument.Save("c:\WebApps-inventory.xml")

PowerShell to Inventory SharePoint Service Applications to XML
Lets Inventory SharePoint 2016 Service Applications:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Create new XML File
[System.XML.XMLDocument]$XMLDocument=New-Object System.XML.XMLDocument

#Add XML Declaration
$Declaration = $XMLDocument.CreateXmlDeclaration("1.0","UTF-8",$null)
$XMLDocument.AppendChild($Declaration)

#Create Root Node "ServiceApplications"
[System.XML.XMLElement]$ServiceAppRootElement=$XMLDocument.CreateElement("ServiceApplications")

#Get all Service applications and loop through
$ServiceApps = Get-SPServiceApplication
Foreach($ServiceApp in $ServiceApps)
{
    $ServiceAppElement = $XMLDocument.CreateElement("ServiceApplication")
    $ServiceAppElement.SetAttribute("TypeName",$ServiceApp.TypeName)
    $ServiceAppElement.SetAttribute("DisplayName", $ServiceApp.DisplayName)
    $ServiceAppElement.SetAttribute("Status", $ServiceApp.Status)    

    #Get the Account and Proxy Group of the Service App
    $ServiceAccountElement = $XMLDocument.CreateElement("ServiceAccount")
    $ServiceAccountElement.Set_InnerText($ServiceApp.ApplicationPool.ProcessAccountName)
    #Append to "ServiceApplication" node
    $ServiceAppElement.AppendChild($ServiceAccountElement)

    $ServiceAppProxyElement = $XMLDocument.CreateElement("ProxyGroup")
    $ServiceAppProxyElement.Set_InnerText($ServiceApp.ServiceApplicationProxyGroup.FriendlyName)
    #Append to "ServiceApplication" node
    $ServiceAppElement.AppendChild($ServiceAppProxyElement)    

    #Append the Service Application data to "ServiceApplications" Node
    $ServiceAppRootElement.AppendChild($ServiceAppElement)
}
# Append Root Node to XML
$XMLDocument.AppendChild($ServiceAppRootElement)

#Save File
$XMLDocument.Save("c:\ServiceAppsInventory.xml")
and it produces the following output:
sharepoint export to xml


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 8, 2016

How to Configure Secure Store Service Application in SharePoint 2016 - Step by Step

Secure store service enables you to securely store credentials required for connecting to external systems and associating those credentials to a specific identity or group of identities.  Secure Store Service solves the problem of having to sign into many applications and entering different usernames and passwords. This is managed through the SharePoint central administration and keeps the credentials stored secure and safe within a secured storage. Secure Store Service was introduced as a replacement to Single Sign-On in MOSS 2007.

Purpose of secure store service in SharePoint 2013
Primary purpose of Secure Store Service is to maintain credentials for target applications on external systems. When we connect to external data sources, it needs to pass the user credentials like user name and password. These type of scenarios we can solve with configure an unattended service account for the external data access.

E.g. When you want to use external data, such as data from your other business applications, in SharePoint, you can use Business Connectivity Services (BCS) together with Secure Store Service. And, you can manage BCS and Secure Store right in the SharePoint central administration site. The external data source that you can connect to is called a Secure Store Target Application. BCS makes it possible for you to set up a connection to the Target Application, and the Secure Store enables you to manage the credentials that are required by the external data source.

SharePoint has its built-in services that can be supported through Secure Store Service. They are as follows:
  • Excel Services
  • Visio Services
  • Business Connectivity Services
  • PowerPivot for SharePoint
  • PerformancePoint Service

How to Create Secure Store Service Application in SharePoint 2016?
Lets see how to create secure store service configuration SharePoint 2016 step by step.
  • Go to SharePoint 2013 Central Administration >> Manage Service Applications
  • In the Service Applications ribbon click on New button and then select Secure Store Service
    how to create secure store service application in sharepoint 2013
  • Enter a name for the Secure store Service Application, database Server and Database name details
    secure store service sharepoint 2013 step by step
  • Scroll down and either choose an existing application pool or create a new application pool using the managed account. To run the application pool, you need a domain account. No specific permissions are required for this account. Click OK to create secure store service.
    secure store service configuration sharepoint 2013
  • Wait for the secure store service application created message.
Generate new key in Secure Store Service:
Secure Store Service requires a key/ pass phrase to encrypt-decrypt credentials. The first time you access the Secure Stored Service it will ask you generate a new encryption key. Before using the Secure Store Service to create target applications, you must provide it with a pass phrase.
  • Go to Central Administration site >>  Application Management
  • Service applications page, pick your newly created Secure store service application.
  • Click on Generate New Key from the ribbonsecure store service in sharepoint foundation 2013
  • Enter the passphrase and click on OK to complete secure store service configuration. Remember it or save a in safe place to have access it when you need.
    use of secure store service sharepoint 2013
Now the error message that displayed on the secure store has gone and it should read something like there are no Secure Store Target Application.

Start the Secure Store Service Instance on the application server(s)
The next step is to start secure store service on the server if its not started already.
  • Go to Central Administration >> System Settings >> Manage service on server (Under Servers).
  • Select the application server >> Locate the Secure Store Service then click start next to it.
The next step is to create Target Application, which I'll explain in an another article.

Technet reference: Configure the Secure Store Service in SharePoint 2013

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, July 6, 2016

How to Get SharePoint Farm ID using PowerShell

Requirement: 
Get SharePoint Farm ID to apply a third party product license to our SharePoint 2016 environment.

How to Get SharePoint Farm ID?
SharePoint farm id is a GUID which is uniquely identifies each farm. To get the Farm Id in SharePoint, use this handy PowerShell code.
(Get-SPFarm).Id
Just open SharePoint 2016 Management Shell and paste this cmdlet in it to find the farm id of the SharePoint Farm. This gets your the SharePoint farm id.
How to Get SharePoint Farm ID using PowerShell
get SharePoint farm guid powershell
You'll get a GUID similar to above screenshot. Although you can query SharePoint Farm config database to get this information, its strongly recommended to use PowerShell, instead of accessing SharePoint database.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, July 4, 2016

How to Disable SharePoint Designer 2013 using PowerShell

SharePoint Designer is a great free tool from Microsoft to customize SharePoint sites and create workflows. Why should we disable SharePoint designer? Well, In some cases site owners and designers may damage SharePoint with this Powerful utility, and I've seen SharePoint designer become SharePoint destroyer! So, to prevent from irreversible damages to SharePoint, we decided to disable SharePoint designer.

You can disable Microsoft SharePoint Designer at Web application & Site collection levels.

Disable SharePoint designer at central administration
To disable SharePoint designer at central administration for a web application, follow these steps:
  • Go to SharePoint 2016 central Administration site >> Click on Application management
  • Click on Manage web applications >> Select your target Web application to disable SharePoint designer
  • From the ribbon, Click on General settings drop down and select SharePoint Designer.
    sharepoint 2013 disable sharepoint designer powershell
  • Unselect all check boxes (or whatever applicable to you) and hit OK to save!
To allow SharePoint designer to be used in this web application, revert the above steps by ticking all check boxes.

SharePoint 2013: Disable SharePoint Designer with PowerShell for a Web Application:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web Application
$webApp = Get-SPWebApplication -Identity "http://intranet.crescent.com/"

#Disable SharePoint Designer
$webApp.AllowDesigner = $False
$webApp.AllowRevertFromTemplate = $False
$webApp.AllowMasterPageEditing = $False
$webApp.ShowURLStructure = $False

$webApp.Update()

Disable SharePoint designer at site collection
SharePoint has the ability to disable SharePoint designer at individual site collection level. Here is how to disable SharePoint designer for a site collection.
  • Login to your SharePoint 2016/2013 site collection(or SharePoint online) as an administrator.
  • Click on Site Settings gear >> Select Site Settings.
  • under Site Collection Administration, select SharePoint Designer Settings.
  • Unselect all the options listed.
    disable sharepoint designer site collection powershell
So from now, SharePoint Designer will be disabled for all users including Site collection Administrators! As this is at site collection level, you'll have to repeat these steps for each site collection!

Disable SharePoint designer for a site collection using PowerShell
Here is the PowerShell script to disable SharePoint designer.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the site
$Site = Get-SPSite "http://intranet.crescent.com/sites/sales"

#Disable SharePoint Designer
$Site.AllowDesigner = $True
$Site.AllowRevertFromTemplate = $True
$Site.AllowMasterPageEditing = $True
$Site.ShowURLStructure = $True 
This Stops SharePoint designer from changing code! To enable SharePoint designer using PowerShell, set the $False flags to $True.
#Disable SharePoint Designer on to all site collections
Get-SPSite -Limit All | ForEach-Object {
    $Site.AllowDesigner = $False
}
How to disable SharePoint designer 2010? Refer my another post: Disable SharePoint designer in SharePoint 2010

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint 2016 Automatic Index Feature

SharePoint 2016 introduces a new feature to automatically create indexes on list fields, Where the list has more items than half of the list threshold value. E.g. If the list threshold is set to 5000 items, and your list has a view with more than 2500 items in it, then the automatic indexing process starts automatically by a daily timer job "Large list column index management Timer Job".

How to Enable Automatic Index on SharePoint List?
This behavior is controlled from Advanced Settings page of the list. If you head on to List Settings >> Advanced settings >> under "Automatic Index Management" section, you'll find an option to turn ON or OFF Automatic Index Management option. By default for all list and library the property is enabled.
sharepoint 2016 automatic index
This setting determines whether this list should automatically start indexing its fields when its item count reaches half of the threshold.

PowerShell to Enable or Disable Automatic Indexing:
Using PowerShell, you can turn this setting on or off by changing the EnableManagedIndexes property on a list.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get Web and List objects
$web = Get-SPWeb "http://intranet.crescent.com/sites/sales"
$List = $web.Lists["Team Documents"]

#Enable Automatic Index
$List.EnableManagedIndexes=$True
$List.Update()
Similarly, You can disable automatic indexing by setting EnableManagedIndexes flag to $False.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Add-Remove Permissions to SharePoint Group or User with PowerShell

Updating the permission level of a SharePoint group or user is fairly straightforward. To add or remove permissions levels of the SharePoint group, Navigate to:
  • Site Settings >> Site permissions
  • Select the person or group you want to change >> Click on "Edit User Permissions" ribbon button sharepoint powershell change group permissions
  • Select or deselect any relevant permission levels required
    sharepoint powershell add remove group permissions
  • Click "OK" to save changes.

PowerShell script to update Permissions of a SharePoint group or User:
Here is my PowerShell script to change permissions of a SharePoint group: Say, We want to remove "Edit" permission level and add "Contribute" to Members group of the SharePoint site.
#assign permission to sharepoint group powershell
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

#Configuration parameters
$SiteURL="http://intranet.crescent.com"
$GroupName="Crescent Intranet Members"
$PermissionToAdd="Contribute"
$PermissionToRemove="Edit"

#Get the Web & Group objects
$Web = Get-SPWeb $SiteURL
$Group = $web.SiteGroups[$GroupName]
$RoleAssignment = $Web.RoleAssignments.GetAssignmentByPrincipal($Group)

#For User, Use:
#$User = $web.EnsureUser("Crescent\Salaudeen")
#$RoleAssignment = $Web.RoleAssignments.GetAssignmentByPrincipal($User)

#Get the permission Levels to Add - Remove
$AddPermissionRole = $web.RoleDefinitions[$PermissionToAdd]
$RemovePermissionRole = $web.RoleDefinitions[$PermissionToRemove]

#Add Permission level to the group
if (!$RoleAssignment.RoleDefinitionBindings.Contains($AddPermissionRole))
{
    $RoleAssignment.RoleDefinitionBindings.Add($AddPermissionRole)
    Write-host "$($PermissionToAdd) Permission Added to the Group!"
}

#sharepoint powershell remove group permissions
if ($RoleAssignment.RoleDefinitionBindings.Contains($RemovePermissionRole))
{
    $RoleAssignment.RoleDefinitionBindings.Remove($RemovePermissionRole)
    Write-host "$($PermissionToRemove) permission removed from the Group!"
}
 
$RoleAssignment.Update()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, July 2, 2016

SharePoint Online: Search Recycle bin using PowerShell

Requirement: Search SharePoint online recycle bin for all files deleted by a particular user

To find all items deleted by a particular user,
  • Navigate to your SharePoint online site, Click on Site Settings Gear >> Choose "Site Settings"
  • From the Site settings page, Click on "Recycle bin" from Site Collection Administration. This page gives you all deleted items in the site collection along with deleted by user data.
    sharepoint recycle bin search
  • PowerShell script to search SharePoint online Recycle bin:
    #Load SharePoint Online Assemblies
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
       
    ##Variables for Processing
    $SiteUrl = "https://crescent.sharepoint.com/sites/Sales/"
    $AdminUserName="Salaudeen@crescent.com"
    $DeletedByUserAccount="salaudeen.rajack@crescent.com"
    
    #Get the password to connect 
    $Password = Read-host -assecurestring "Enter Password for $AdminUserName"
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUserName,$Password)
     
    Try {    
        #Setup the context
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
        $Context.Credentials = $Credentials
        
        #Get the site recycle bin
        $Site = $Context.Site
        $RecycleBinItems = $Site.RecycleBin
        $Context.Load($Site)
        $Context.Load($RecycleBinItems)
        $Context.ExecuteQuery()
    
        #Get all items deleted by particular user in Recycle bin
        $DeletedByUser = $RecycleBinItems | Where {$_.DeletedByEmail -eq $DeletedByUserAccount}
        Write-Host "Total Number of Items deleted by user:" $DeletedByUser.Count
        
        #format output as table and print to console
        $DeletedByUser | Select Title, DeletedByEmail, DeletedDate | Format-Table
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }


    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    SharePoint Online: Restore a document from the recycle bin using PowerShell

    Task: Recover a deleted document from the recycle bin in SharePoint online.

    How to restore from recycle bin in SharePoint online?
    • Login to your SharePoint online site and click "Site Contents" from either site settings gear or from left navigation.
    • Click on "Recycle bin" link from the top of the page.
    • Select the document(s) you would like to restore and then click "Restore Selection".
      sharepoint online restore from recycle bin
    • Confirm restore by clicking "OK" button.
    • The files you selected is available in the original location from where it was deleted.

    SharePoint online: restore from recycle bin using PowerShell
    Now, lets use PowerShell to restore all excel files from recycle bin. 
    #Load SharePoint Online Assemblies
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
       
    ##Variables for Processing
    $SiteUrl = "https://crescent.sharepoint.com/sites/Sales/"
    $UserName="Salaudeen@crescent.com"
    
    #Get the password to connect 
    $Password = Read-host -assecurestring "Enter Password for $UserName"
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)
     
    Try {    
        #Setup the context
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
        $Context.Credentials = $Credentials
        
        #Get the web recycle bin
        $Web = $Context.web
        $RecycleBinItems = $Web.RecycleBin
        $Context.Load($Web)
        $Context.Load($RecycleBinItems)
        $Context.ExecuteQuery()
    
        #Get all Excel files from Recycle bin
        $ExcelFiles= $RecycleBinItems | Where {$_.Title -like "*.xlsx"}
        Write-Host "Total Number of Excel Files found Recycle Bin:" $ExcelFiles.Count
        
        #Restore from Recylce bin
        $ExcelFiles | ForEach-Object { $_.Restore() }
        $Context.ExecuteQuery()    
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
    Please note that the above script restores from 1st stage recycle bin (or end-user recycle bin). Instead of Web object, you may have to use Site object if you want to restore from Site collection Recycle bin (Or 2nd stage recycle bin).

    You might also like:
    SharePoint Usage Reports
    Usage reports, collaboration and audit for SharePoint.
    Document SharePoint Farm
    Automatically generate SharePoint documentation.
    *Sponsored


    You might also like:

    Related Posts Plugin for WordPress, Blogger...