Tuesday, December 20, 2016

Add Links to Resources List in SharePoint Central Administration

The Resources list in SharePoint Central Administration site lets you to keep frequently accessed links to the home page. Say for e.g. To access User profile service application, you'll have to navigate through:
  • Central Administration >> Application Management 
  • Manage Service Applications >> Search and pick your user profile service Application
in some other cases, you'll find a difficulty in navigating To-And-Fro in SharePoint Central Administration. So, Resources list comes handy to manage this hassle. Just add your frequently accessed links to it! When you log into SharePoint Central Administration site, you'll see the Resources link list in right pane.
Consider Resources list as your Favorites or Bookmarks List!
sharepoint 2013 central admin resources list
To Add a link/remove links in resources list:
  • Click on "Resources" link from SharePoint Central Admin home page (or your can Click the gear icon and click Site Contents >>  Find the Resources list)
  • From here you can add or delete the link like any list item.
    sharepoint 2013 add link to resources list in central admin
This saves time and effort, especially if you have trouble finding service applications in Central Admin.

Populate Resources List using PowerShell:
Lets use PowerShell to add items to Resources list in SharePoint Central Administration site.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Get Central Administration Site
$CentralAdminUrl = Get-SPWebApplication -includecentraladministration | where {$_.IsAdministrationWebApplication} | Select -ExpandProperty URL

#Get Resources list from Central Admin
$List = (Get-SPWeb -identity $CentralAdminUrl).Lists["Resources"]

#Get Service Applications to add to Resources List
$ServiceApps = Get-SPServiceApplication | Where {($_.TypeName -eq "Excel Services Application") `
                                 -or ($_.TypeName -eq "Managed Metadata Service") `
                                 -or ($_.TypeName -eq "User Profile Service Application") `
                                 -or ($_.TypeName -eq "Search Service Application") `
                                 -or ($_.TypeName -eq "Business Data Connectivity Service Application") }

#Loop through and Add Links to Resources list
foreach ($App in $ServiceApps)
{
    $Item = $List.Items.Add()
    $Item["URL"] = "$($App.ManageLink.Url), $($App.DisplayName)"
    $Item.Update()
}

Write-Host "Service Application Links added to Resource List!" -f Green


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


Thursday, December 15, 2016

How to Create SharePoint 2016 Farm using PowerShell

Creating SharePoint 2016 farm using PowerShell is almost as same as in its previous version. In SharePoint 2016 there is an additional parameter -LocalServerRole added as SharePoint 2016 introduced MinRoles.

Pre-Requisites:
  • SQL Server is already installed and ready to use.
  • You have created a Farm account for SharePoint 2016.
  • You have logged in to the server (Setup account) which has Administrator access on all SharePoint servers and DB_Creator, Security_Admin Server roles in SQL Server.

Step 1: Install SharePoint 2016 prerequisites and binaries to each server in your proposed SharePoint 2016 farm.
install sharepoint 2016 farm using powershell
On completing the installation, Uncheck "Run the SharePoint Products Configuration Wizard now" and close the wizard.
create new sharepoint 2016 farm with Powershell

Step 2: PowerShell Script to Create SharePoint 2016 Farm:
Save the below script as "Create-Farm.ps1" or something like that, change the configuration settings parameters as per your environment. Open SharePoint 2016 Management Shell as Administrator, and run the script. You'll see
"The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered."  error for the first time, which is quite normal, since we have not created the Farm yet! proceed running the script.

#Configuration Settings 
$DatabaseServer = "SP16-SQL"
$ConfigDatabase = "Intranet_Farm_Config"
$AdminContentDB = "Intranet_Farm_Content_Admin"
$Passphrase = "2FJlsXghFsas5vdJJKEXXwWF"
$FarmAccountName = "Crescent\Sp2016admin"
$ServerRole="SingleServerFarm"

#Get the Farm Account Credentials
$FarmAccount = Get-Credential $FarmAccountName
$Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
  
#Create SharePoint Farm
Write-Host "Creating Configuration Database and Central Admin Content Database..."
New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmAccount -LocalServerRole $ServerRole

$Farm = Get-SPFarm -ErrorAction SilentlyContinue -ErrorVariable err  
if ($Farm -ne $null) 
{
Write-Host "Installing SharePoint Resources..."
Initialize-SPResourceSecurity
 
Write-Host "Installing Farm Services ..."
Install-SPService
 
Write-Host "Installing SharePoint Features..."
Install-SPFeature -AllExistingFeatures
 
Write-Host "Creating Central Administration..."              
New-SPCentralAdministration -Port 2016 -WindowsAuthProvider NTLM
  
Write-Host "Installing Help..."
Install-SPHelpCollection -All  
 
Write-Host "Installing Application Content..."
Install-SPApplicationContent
  
Write-Host "SharePoint 2016 Farm Created Successfully!"
} 
Once the script completed successfully, You'll see farm created successfully message. Here I've used "SingleServer" as MinRole. You can adjust it based on your requirement.
Alternatively, You can create SharePoint Farm (Run script til line#15) and then Run Products configuration wizard to complete the rest of the steps in farm creation.

Add Additional Servers to the SharePoint 2016 Farm:
Once you are done with the creation of the SharePoint 2016 farm from first server, You can connect rest of the servers to the Farm either using SharePoint products configuration wizard or with PowerShell.

Open SharePoint products configuration wizard and choose "Connect to an existing server farm" and run through the wizard! Select the server MinRole as per your topology.
powershell script to create sharepoint 2016 farm

Join Additional Server to the SharePoint 2016 farm using PowerShell:
If you prefer PowerShell way to add an additional server to the farm, use this PowerShell script.  
$ServerRole="Application"
#"Custom","WebFrontEnd","Application","DistributedCache","SingleServerFarm","Search","ApplicationWithSearch","WebFrontEndWithDistributedCache"

Connect-SPConfigurationDatabase -DatabaseServer $DBServer -DatabaseName $DBName -PassPhrase $SecurePassPhrase -LocalServerRole $ServerRole
 
Write-Host "Installing SharePoint Resources..."
Initialize-SPResourceSecurity
 
Write-Host "Installing Farm Services ..."
Install-SPService
 
Write-Host "Installing SharePoint Features..."
Install-SPFeature -AllExistingFeatures
 
Write-Host "Installing Help..."
Install-SPHelpCollection -All  
 
Write-Host "Installing Application Content..."
Install-SPApplicationContent
  
Write-Host "Joined the Server to Farm Successfully!"
If you don't want the server to host Distributed cache, use the parameter: -SkipRegisterAsDistributedCacheHost and the end!
Related post: How to Create SharePoint 2013 farm using PowerShell

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


Wednesday, December 14, 2016

Open this link on a Phone - QR Code Feature in SharePoint 2016

SharePoint 2016 introduces a new feature to open links on your phone or tablet using QR codes. Here is how this feature works:
  • Go to any of your SharePoint 2016 library such as document library. From the document's context menu, click on the tiny phone icon.
    QR Code Open this link on a phone Feature in SharePoint 2016
  • This takes you to a page with QR code generated for the document URL. By default, every document is assigned with a Unique QR code.Open documents with QR code in sharepoint 2016
  • From your phone, use QR reader app to read the QR code and navigate to the document URL. This makes easier to share documents on mobile devices.


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


Thursday, December 8, 2016

How to Create State Service Application in SharePoint 2016

Lot of components like InfoPath Form services, Visio, Search Service, workflows, etc relies in State Service Application of SharePoint to store the application sessions. If its not configured already, you'd probably see error messages such as:

"The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator."

How to Create State Service application in SharePoint 2016?
State service application can't be created through new service application page. If you go to New dialog of Central Administration >> Manage Service Application page, you won't find it! here is how to create state service application in SharePoint 2016.
  • Go to Central Administration site >> Click on "Configuration Wizards" link from the bottom
  • In Configuration Wizards page >> click Launch the Farm Configuration Wizard link >> and then click "Start the Wizard".
    sharepoint 2013 configure state service application
  • On the services configuration page, under Services applications section, select the State Service check box (select any other service applications you may require) and click Next.
    create state service application sharepoint 2016 powershell
  • Click on Skip button if you set-up a top-level site collection. If not, go ahead and create it now by clicking OK.
You can verify the new state service application by: going to Central Administration > Application Management > Manage service applications >> State service application should be listed there!
create state service application sharepoint 2016
Once you created state service application, make sure your new state service application is associated with your web application by going to Central Administration >> Manage Web Applications >> Select your web application >> Click on "Service Application Associations" from the ribbon >> and in "Configure Service Application Associations" page, State Services should be selected.

Disadvantage: Configuration wizard creates state service database with GUIDs! E.g. StateService_2349fb4359fb45c9a5255562cb0eab0b. So, to avoid GUIDs in database, Create State service application using PowerShell:

SharePoint 2016: Create State Service Application using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration variables
$ServiceAppName = "State Service Application" 
$ServiceAppProxyName ="State Service Application"
$DatabaseName ="SP16_State_Service"

#Create New State Service application
$StateServiceApp = New-SPStateServiceApplication -Name $ServiceAppName 

#Create Database for State Service App
$Database = New-SPStateServiceDatabase -Name $DatabaseName -ServiceApplication $StateServiceApp  

#Create Proxy for State Service
New-SPStateServiceApplicationProxy -Name $ServiceAppProxyName -ServiceApplication $StateServiceApp -DefaultProxyGroup  

Initialize-SPStateServiceDatabase -Identity $Database

Write-host "State Service Application Created Successfully!"


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


Tuesday, December 6, 2016

Configure My Sites in SharePoint 2016 - Step by Step Guide

SharePoint 2013 & SharePoint 2016 brought new social networking capabilities to the SharePoint collaboration space. With My Sites users can store documents, keep-up their profile information, news feed, contribute to the organization via blogs, follow activities on sites, people, tags, documents, etc! In short: My Site is the personal space for individual users in an organization. At high level, configuring my sites in SharePoint 2016 involves following steps:
  1. Create a dedicated web application & My Site host site collection
  2. Add a wildcard inclusion managed path to the web application
  3. Enable self-service site creation for the web application
  4. Create a permission policy & Grant everyone permission to My Site web application
  5. Configure My Site settings for the User Profile service application
This article walks you through step by step on creating and configuring My Sites for SharePoint 2016. Although this article aims at SharePoint 2016, same steps are applicable to SharePoint 2013 as well.

Prerequisites:
Before you create My Sites in SharePoint, you need to have the following services properly configured.
  • User Profile Service application - SharePoint My Sites depends on UPS! User Profile Service Application will be used to map the My Sites with the User Profiles.
  • Managed Metadata service application -  My Site users Keywords! so have MMS created  & configured prior setting up My Sites.
  • Search service application - not mandatory, but best practice for people search results!
Also make sure User Profile Service Application, Managed Metadata Service, and Search Service Application are up running and they are connected to your My site web application through service connections in Central Admin.

Step 1: Create New web application for My Sites

Although you can use an existing web application, its a best practice to create a dedicated web application for My sites for reasons like security, performance, etc. So, To start with, lets create a dedicated web application to host our my sites in SharePoint 2016.
  • Open SharePoint 2016 Central Administration site.
  • From Application Management >> Click the Manage Web Applications >> Click New to Create New Web Application.
  • Provide a Name, Port, Host Header, and fill the rest of the new web application form. Hit OK to create new web application.
create my site host sharepoint 2013

Create My Site Host Site Collection in SharePoint 2016:
Once the web application is created, proceed with creating a site collection in the root of the web application.
  • From SharePoint 2016 Central Administration, select Application Management and then select Create site collections
  • Select the Web application we created in the previous step. 
  • Provide a name and description to the site collection.
  • Choose the "My Site Host" as template.
  • Provide a primary site collection administrator.
  • Leave the quota option default.
  • Click the OK button to create the site collection.
create my site host sharepoint 2016

Step 2: Add new managed path to the My Site Web Application:

Managed paths defines the location to host site collections within a web application. In our environment, When SharePoint users provision their My Sites, we would like them to reside at http://mysite.crescent.com/personal/name-of-person/. So, We defined a wildcard managed path for "/personal/" as follows:
  • From SharePoint Central Administration >> Manage Web Application >> Select the My Site Host Web Application you just created.
  • In the ribbon click the Managed Paths button >> Define Managed Paths dialog, Add a new path called "personal" (or "my" or whatever you like!) and make it Wildcard inclusion. Click "Add Path" and then OK once done.
  • Optionally, You can delete the OOTB "Sites" managed path from My site web application.
    sharepoint mysite configuration

Step 3: Enable self-service site creation for the web application

Self-service site creation option enables the end user to create their own My site collection automatically.
  • Select your web application from Manage Web Applications page of Central Administration site.
  • Click on "Self Service Site Creation" button for the web application
    configure my site sharepoint 2013
  • Select "On" for Site Collections and "Prompt users to create a team site" under Start a Site. Provide the managed path we created ("/personal"). Leave the rest default.
    sharepoint 2013 my site step by step

Step 4: Add Permission Level Policy & User Permission to My Site Web Application (Optional):

Perform this step only when you want your users to create subsites under my site site collection. Create a permission level policy with "Create Subsites" rights.
  • Select your My Site web application and Click on the "Permission Policy" button from the ribbon. In the "Manage Permission Policy Levels", click on "Add Permission Policy Level" link.
    sharepoint 2016 mysite web application
  • Under Permissions, scroll to Site Permissions, select the Grant option for "Create Subsites - Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites". Now, the new permission policy level should appear among other policy levels.
    sharepoint 2016 my sites configuration
  • You need to grant that policy level to all users. Highlight your my site web application, Click on the "User Policy" button from the ribbon.
  • Click on "Add users" link >> Choose All zones and enter the users as "Everyone". Click OK to commit your changes.
    sharepoint 2013 my site creation

Step 5: Configure My Site URL in the User Profile Service Application

Alright, Now you have a My Site Web Application, My Site Host root site collection,  wildcard managed path and self-service enabled for the web application. The only remaining thing would be to set up My Site URL on User Profile Service Application, So that user profile service knows where to create new site collections for user My Sites. 
  • Go to Central Administration >> Application Management >> Manage service applications.
  • Select your User Profile Service Application >> On the Manage User profile service page, in My Site Settings section, click on "Setup My Sites" link.
    sharepoint 2013 my site step by step
  • Enter the My Site Host URL and click Save.
  • Specify other settings like Personal Site Location, Site Naming Format, Secondary Owner, etc.
Each My Site exists as a separate site collection to provide security isolation in SharePoint.

Optional: Set up interval for activity feed timer job
  • Go to the Central Administration >> Monitoring >> Timer Job >> Review job definitions
  • Find "User Profile Service Application - Activity Feed Job", and set up the activity feed sync time according to your needs. By default, its set to run for every 10 Minutes.

Create My Sites in SharePoint 2016:
So, we completed all configurations to get My sites up and running. Lets perform a quick test.
  • Go to any of the SharePoint site in the farm and select "About Me" link from the welcome menu.
  • You will redirected to your personal My Site home page if all fine, Where you can edit Your personal details like profile picture, contact information etc.
    sharepoint my site configuration
My Site Quota & Content Database sizing - Best Practices:
Setup Storage Quota for My Sites! By default, this setting is unlimited. - But you don't want your SQL disks get filled by My Sites, isn't it?

By default, The maximum number of site collections created per content database is 5000. If you are planning for 10,000 My Sites, of 100 GB each you'll need 1000 TB disk space! So, plan to adhere Content database sizing recommendation - 200 GB or less per content database for better performance.

Technet reference: Configure My Sites in SharePoint Server 2016


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


Friday, December 2, 2016

Shared MinRoles in SharePoint 2016 Feature Pack 1

MinRole was an exciting new feature introduced in SharePoint 2016. In Simple words, based on the MinRole you select during setting up your Farm, SharePoint 2016 automatically takes care of services to run on that server and optimizes it to delivers better performance and reliability. However, the downside is: You need Eight SharePoint servers to have an highly available SharePoint 2016 farm!

So now with Feature pack 1, You can combine Web Front End and Distributed Cache roles - Application and Search roles together! and you just need Four servers to have a highly available SharePoint 2016 farm instead of Eight! Apart from MinRoles enhancement, Feature pack 1 also brings features such as: Central Administration Administrative Actions Logging, Custom Tiles in the SharePoint app launcher, Hybrid Auditing, Hybrid Taxonomy, OneDrive API, etc.

If you have installed Feature pack 1 prior creating SharePoint 2016 farm, this how it looks like on farm creation wizard:
Shared MinRoles in SharePoint 2016 Feature Pack 1
If your SharePoint farm is already created, you can switch the MinRoles from SharePoint 2016 Central Administration site: How to switch Server's MinRole in SharePoint 2016

How to Install Feature Pack 1 in SharePoint 2016?
Download and install November 2016 CU which brings the Feature pack 1 for SharePoint 2016. In addition, If you have language packs installed in your farm, you need to download and install the November 2016 CU Language pack fix (Optionally, you can download and install all other updates from Technet - SharePoint 2016 Updates ,
Don't forget to run SharePoint products configuration wizard once After the installation!


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


Wednesday, November 30, 2016

SharePoint Online: Update Created By / Modified By, Created At / Modified At Field values using PowerShell CSOM

At times, you may have to create list items or set existing item's metadata fields such as Created by, Modified by, Created at, Modified values to a specific user - time stamp. Say, You are importing or migrating data from a network file share to SharePoint online and you want to keep these metadata as same as the source content.

Because, SharePoint doesn't let you to set these values from web user interface, we've to use PowerShell. Here is my PowerShell script to change the details of who created an item, modified it and when they created and modified it.

This script sets system fields (created, created by, modified, modified by) for a specific item in the list/library. Set the values in variables section appropriately and run the script.

PowerShell script to update Created by, Modified By, Created at, Modified at field values:
This PowerShell script sets item's metadata field values in SharePoint online
#Load SharePoint CSOM 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/"
$ListName= "Projects"
$ID=6
$UserID="Salaudeen@crescent.com"
$TimeStamp = "2015/12/01 02:10:00 AM"

#Get Credentials to connect
$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $Credentials

#Get the User
$User = $Ctx.Web.EnsureUser($UserID)
$ctx.Load($user)

#Get the list Item
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ID) 
$Ctx.Load($ListItem)

#Update Created by & Modified By
$ListItem["Author"] = $User
$ListItem['Editor'] = $User

#Set Created on & Modified on Time values
$ListItem["Created"] =  $TimeStamp
$ListItem["Modified"] = $TimeStamp

#Update List item
$ListItem.Update()
$ctx.ExecuteQuery()

Write-host "Metadata values updated Successfully!" -f Green
and the result goes here:
sharepoint online powershell to update created by modified by created at modified at values
For Server side PowerShell script, refer: Update "Created By", "Last Modified" Metadata Fields of a List Item using PowerShell

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


Tuesday, November 15, 2016

Fix for "Cannot Connect to Database Master at SQL Server at Server Name - The Database might not exist, or the current user does not have permission to connect to it" SharePoint Error

Problem:
When trying to create a new SharePoint farm using PowerShell, the SharePoint 2016 management Shell gave an error message:
New-SPConfigurationDatabase : Cannot connect to database master at SQL server at <SQL-Server-Alias>. The database might not exist, or the current user does not have permission to connect to it.
New-SPConfigurationDatabase : Cannot connect to database master at SQL server at SP16_SQL. The database might not exist, or the current user does not have permission to connect to it.
Tried using SharePoint products configuration wizard as well and got the same issue!

Troubleshooting Checklist:
  1. Check the permissions for the Setup account which you are using to run the wizard or PowerShell. Make sure the setup account is granted with "DB_Creator" and "Security_Admin" Server Roles.
  2. In case of Named instance, it should be "Server\InstanceName". If is is SQL Alias, make sure the alias is properly configured and should be accessible from SharePoint Server. Verify if the SQL Server Alias is created for both 32 and 64-bit! How to Create SQL Server Alias for SharePoint
  3. Check if the SQL Server Service is running on your Database Server. Verify "TCP/IP" protocol is enabled under Network Configuration section of SQL Server Configuration Manager. 
  4. Test the connectivity between SharePoint and SQL Server. Try adding a HOST file entry in your SharePoint Server to point the SQL Server's IP!
  5. Check the firewall rules on SQL Server. If firewall is enabled on SQL Server, Create inbound TCP rule with ports: 1433,2383,2382. and inbound UPD rule with port: 1434.
  6. Double check if you have not fat-fingered User Name or Password!


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


Tuesday, November 8, 2016

How to Create New Target Application ID in Secure Store Service for BCS in SharePoint 2016

When you want to consume external data in SharePoint, such as data from your other business applications, you can use Business Connectivity Services (BCS) together with Secure Store Service. 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

Before proceeding, You have created and configured Secure store service application and generated the master key from SharePoint 2013/2016 Central Administration site, isn't it? If not, Refer:
Now you are all set to create new Target Applications and use in SharePoint. Here you go!

How to Create New Target Application ID?
Here are the steps to Add new Target Application ID in SharePoint 2016 Secure store Service:
  • Go to SharePoint Central Administration site >> Click on "Manage Service Applications"
  • Locate and pick your Secure store service application
  • In the Ribbon, Under the Edit tab click on New button
  • Enter the Target Application ID (Make sure the ID is unique - and you can't change it later), Display Name, Contact E-Mail. Choose the application type - Group: Maps group of users to a single set of stored credentials Individual: Maps a single user to a single set of stored credentials. Click Next.
    sharepoint secure store application id
  • The next window gives you the ability to Add/Change credential fields associated with the external data source. In my case, I left it with Windows User Name and Windows Password fields as they are sufficient to connect with SQL Server database using windows credentials. Click on Next.
    If you want to use SQL authentication , Select "User Name" and "Password" in Field type dropdown
    sharepoint secure store application id 2013
  • Enter the name(s) of the users that will administer the target application and Group who will use the target application and click OK
    sharepoint 2013 secure store target application type
Now we have successfully created target application.  

Set up Credentials for New Target Application ID:
The next step is to set the credentials for the target application ID.
  • Click on Context menu of newly created Target Application Id and choose Set Credential
    sharepoint 2016 create secure store application id
  • Enter the User Name and Password & Confirm Password which will be used to connect to the target data source on behalf of authorized users and click on OK to complete the creation of secure store target application ID. Make sure this access account (In my case its: Crescent\DBAccess) have proper rights on external database for the operation such as Read/Write.
    sharepoint designer secure store application id
Now All users of the given group can use the Application ID to connect with external data source with the application ID generated! Once the target application is created in Secure store service, you can associate it with any application to interact with the external database or application model, such as from SharePoint Designer, Excel, etc.

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


SharePoint Online: How to Hide a List or Library using PowerShell

Requirement: Hide a list or library from SharePoint Online site.

SharePoint Online: Hide Document Library using PowerShell
There are many ways to hide a SharePoint online list. Here is the PowerShell CSOM script to create hidden lists in SharePoint online.  
#Load SharePoint CSOM 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"
  
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$LibraryName="ProjectConfig"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
  
    #Get the web and Library
    $Web=$Ctx.Web
    $List=$web.Lists.GetByTitle($LibraryName)

    #Hide the list
    $List.Hidden = $True
    $List.Update()
    $Ctx.ExecuteQuery()
     
    Write-host -f Green "List hidden Successfully!"
}
Catch {
    write-host -f Red "Error hiding List: " $_.Exception.Message
}
You can also use SharePoint designer to mark a list hidden from browser. Read more here: How to hide a list in SharePoint?
how to hide list in sharepoint online

Tags: sharepoint online hidden list, sharepoint online hide task list, sharepoint online create hidden list, sharepoint online hide document library, sharepoint online hide library

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


Thursday, October 27, 2016

Copy Permissions from One SharePoint Site to Another using PowerShell

Requirement: Copy permissions from one site to another in SharePoint!

Solution: If you want to copy one SharePoint site to another site, there is no OOTB ways! However, You can use PowerShell to copy permissions between sites. Here is my PowerShell script to copy site permissions.

Copy Permissions from one site to another using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
 
#PowerShell Function to copy permissions from one site to another
Function Copy-SitePermissions()
{
 param(
     $SourceWebURL,
     $TargetWebURL
 )
 Try {
  #Set the Error Action
    $ErrorActionPreference = "Stop"
  
  #Get the Source and Target Webs
  $SourceWeb = Get-SPWeb $SourceWebURL
  $TargetWeb = Get-SPWeb $TargetWebURL
  
  #if permissions are Inherited in the target, Break it!
  if($TargetWeb.Permissions.Inherited)
  {
   #Reset the Inheritence in Target Web
   $TargetWeb.BreakRoleInheritance($false)
  }
   #Copy permissions from Source to Target Web
     $SourceWeb.RoleAssignments | foreach-object {
     $TargetWeb.RoleAssignments.Add($_)
     }
    $TargetWeb.Update()
    Write-Host "Permissions copied from Source Site to the Target!" -f Green
 }
 catch {
   Write-Host $_.Exception.Message -ForegroundColor Red
 }
 finally {
  #Reset the Error Action to Default
  $ErrorActionPreference = "Continue"
 }
}

#Call the function to copy Web permissions 
Copy-SitePermissions -SourceWebURL "http://portal.crescent.com/ProjectHub/" -TargetWebURL "http://portal.crescent.com/TaxAudits/" 


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


Sunday, October 23, 2016

Customize Suitebar Text and Link in SharePoint 2016 using PowerShell

Requirement:
By default, SharePoint 2016 comes with "SharePoint" as the suitebar branding text.  What if you would like to change it to something meaningful, say "Your Company Intranet"? Well, PowerShell can help to customize the branding text, Logo and URL in SharePoint 2016.
sharepoint 2016 add link to suite bar powershell
PowerShell Script to change Suitebar navigation text and link:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebApp= Get-SPWebApplication "http://intranet.crescent.com"
$WebApp.SuiteNavBrandingText = "Crescent Portal"

#Blank image from Layouts folder
$webapp.SuiteNavBrandingLogoUrl = "/_layouts/images/dot_ruleper.gif"
$webapp.SuiteNavBrandingLogoTitle = "Crescent Logo"
$webapp.SuiteNavBrandingLogoNavigationUrl = "http://portal.crescent.com"
$webapp.Update()

Here is the result of customized SharePoint 2016 suite bar branding using PowerShell!
customizing the sharepoint 2016 suite bar branding using powershell
My another post Customizing the SharePoint 2013 suite bar branding using PowerShell

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


Saturday, October 22, 2016

SharePoint Online: Delete Site Column using Powershell

Requirement: Delete Site Column in SharePoint online using PowerShell

How to delete a site column in SharePoint online?
To remove a SharePoint online site column, follow these steps:
  • Go to Site Settings by clicking Site settings gear and then "Site settings" from the menu.
  • Click on "Site Columns" link from Web Designer Galleries group >> Select the site column to delete.
  • Scroll down and click on "Delete" button and confirm the prompt to delete.
    sharepoint online powershell delete site column
This removes a site column in SharePoint online.

SharePoint online PowerShell to delete site column:
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL and Site column Title
$SiteURL= "https://crescent.sharepoint.com/sites/sales"
$ColumnName="Sales Region" #Case sensitive

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Check if the site column exists
    $Fields = $Ctx.web.Fields
    $Ctx.Load($Fields)
    $Ctx.ExecuteQuery()
    $FieldNames = $Fields | select -ExpandProperty Title

    #delete site column in sharepoint online
    If($FieldNames.Contains($ColumnName))
    {
        #Delete the site column
        $SiteColumn = $Fields.GetByTitle($ColumnName)
        $Sitecolumn.DeleteObject()
        $Ctx.ExecuteQuery()

        Write-host -f Green "Site Column Deleted Successfully!"
    }
    else
    {
        Write-host -f Yellow "Site Column Doesn't Exists!"
    }
}
Catch {
    write-host -f Red "Error deleting Site Column!" $_.Exception.Message
} 


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


How to Delete a SharePoint Web Application

SharePoint Web Applications are actually an IIS Containers at top level. Each web application we create from SharePoint, creates respective site in IIS and a content database in SQL Server.

To delete a SharePoint 2016 Web Application,
  • Open SharePoint 2016 Central Administration Site
  • Click on "Manage web applications" link under "Application Management"
  • Select your target web application, and from the ribbon, click on Delete button.
    how to delete a web application in sharepoint 2013
  • Specify whether you would like to delete the content databases and IIS web sites.
    how to delete a sharepoint web application
  • Confirm the Prompt once to delete a web application in SharePoint 2013 and your web application will be deleted momentarily.
This removes the specified web application from the SharePoint farm.

SharePoint delete web application zone:
To delete SharePoint web application extension, From SharePoint Central Administration:
  • Click on Administration Management >> Manage Web Applications
  • Select the web application you wish to remove the extended zone from >> Click on Delete button drop-down and choose "Remove SharePoint from IIS Web Site"
  • Select IIS web site & zone to remove, (make sure its not your "Default" zone!)
  • Set the value for "Delete IIS web sites" to "Yes" and click OK to delete web application zone.
    sharepoint delete web application zone
To delete a SharePoint web application using PowerShell, use this script: Delete SharePoint web application using PowerShell

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


Wednesday, October 19, 2016

SharePoint Online: Delete List using PowerShell CSOM

How to Delete a list or library in SharePoint Online:
  • Click on Site Settings gear >> Select Site contents from the menu.
  • On the site contents page, Hover over the list or library that you want to delete and then click the drop-down menu icon (…)
  • On the menu that appears, click on "Remove" link and then confirm the prompt to send the list to the Recycle Bin. 
  • Alternatively, you may remove a list or library in SharePoint online by going to list settings >> Click on "Delete this list" under Permissions and Management group.
    delete list sharepoint online powershell
Delete List in SharePoint Online using PowerShell:
SharePoint online PowerShell to delete list
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL and List Name
$SiteURL= "https://crescent.sharepoint.com/sites/pmo"
$ListName="Projects"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)

    #Delete the list
    $List.DeleteObject()
    $Ctx.ExecuteQuery()
        
    Write-host -f Green "List Deleted Successfully!" 
}
Catch {
    write-host -f Red "Error deleting list!" $_.Exception.Message
}


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


Monday, October 17, 2016

SharePoint Online: Configure Access Request Email Settings using PowerShell

Access request settings in SharePoint Online
Access Request feature in SharePoint online allows people to request access to content that they do not have permission. Access request settings also allows members of the site to send invitations to users who have no permission. Once the invitations are sent, Site owner should approve it from Site settings >> Access requests and invitations. If you change these settings on the Site Collection level, then new sub sites doesn’t inherit. 

To configure access request email settings in SharePoint online, Go to
  • Site Settings >> Site Permissions >> Access Requests Settings 
  • This takes you to SharePoint online access request page >> Update access request email and hit OK to save your changes.sharepoint online access request settings powershell
Please note, SharePoint online access request email Site Settings must be configured at each site level.

Configure SharePoint online access request settings using PowerShell
Use this PowerShell script to update SharePoint online access request email.
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$AccessReqEmail="SharePointSupport@crescent.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the current settings
    $Web = $Ctx.Web
    $Ctx.Load($web.AllProperties)
    $web.RequestAccessEmail
    $Ctx.ExecuteQuery()

    #Set Access request Email
    $Web.RequestAccessEmail =$AccessReqEmail
    #Member settings
    $Web.MembersCanShare = $True
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $True
    $web.AssociatedMemberGroup.Update()

    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error configuring Access request settings!" $_.Exception.Message
}

Disable access request in SharePoint online:
To disable access request, simply clear the Email value!
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #disable Access request
    $Web = $Ctx.Web
    $Web.RequestAccessEmail = ""
    $Web.MembersCanShare = $False    
    $web.AssociatedMemberGroup.AllowMembersEditMembership = $False
    $web.AssociatedMemberGroup.Update()
    $Web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error disabling Access request settings!" $_.Exception.Message
}


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


Get All Users and Groups in SharePoint Online Site using PowerShell-CSOM

Requirement: Get All Users and Groups Report in SharePoint Online using PowerShell-CSOM

PowerShell Script to Get All Users and Groups Report in SharePoint Online:
This PowerShell script gets all groups and users of each group in a SharePoint online site.
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get all Groups
    $Groups=$Ctx.Web.SiteGroups
    $Ctx.Load($Groups)
    $Ctx.ExecuteQuery()

    #Get Each member from the Group
    Foreach($Group in $Groups)
    {
        Write-Host "--- $($Group.Title) --- "

        #Getting the members
        $SiteUsers=$Group.Users
        $Ctx.Load($SiteUsers)
        $Ctx.ExecuteQuery()
        Foreach($User in $SiteUsers)
        {
            Write-Host "$($User.Title), $($User.Email), $($User.LoginName)"
        }
    }
}
Catch {
    write-host -f Red "Error getting groups and users!" $_.Exception.Message
}
Here is my another article to get all groups and group members from SharePoint online using SharePoint online shell: SharePoint Online: Site Users and Groups Report using PowerShell

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


Sunday, October 16, 2016

SharePoint Online: Get Content Type ID using PowerShell-CSOM

My other article speaks on How to find the content type id in SharePoint, using SharePoint UI and PowerShell for SharePoint On-premises, This post provides script to get content type by id programmatically for SharePoint online.
To get the content type ID, you can Go to List/Site Content Types >> Pick your content type >> The URL will have "Ctype" parameter with the content type ID!
sharepoint online get content type id

SharePoint Online: Get content type id using CSOM
Here is the PowerShell script to get content type id in SharePoint using csom code.
#Load SharePoint CSOM 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"
  
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$ContentTypeName="Crescent Project Report"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get content types of the web
    $ctx.Load($ctx.Web.ContentTypes)
    $Ctx.ExecuteQuery()

    #Get the content type by its name
    $ContentType = $Ctx.Web.ContentTypes | Where {$_.Name -Match $ContentTypeName}
    $Ctx.Load($ContentType)    
    $Ctx.ExecuteQuery()

    #sharepoint online get content type id
    write-host -f Green "Content Type ID:" $ContentType.Id
}
Catch {
    write-host -f Red "Error Getting Content Type ID!" $_.Exception.Message
} 
Get content type id from SharePoint online List
Lets get Content Type id for a List content type:
#Load SharePoint CSOM 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"
  
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$ListName="Projects"
$ContentTypeName="Project Portfolio"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the List and Its content types
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.load($List)
    $Ctx.load($List.ContentTypes)
    $Ctx.ExecuteQuery()

    #Get the content type by its name
    $ContentType = $List.ContentTypes | Where {$_.Name -Match $ContentTypeName}
    $Ctx.Load($ContentType)    
    $Ctx.ExecuteQuery()

    #sharepoint online get content type id
    write-host -f Green "Content Type ID:" $ContentType.Id
}
Catch {
    write-host -f Red "Error Getting Content Type ID!" $_.Exception.Message
}


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


How to Get Content Type ID in SharePoint using PowerShell

Requirement:
A typical usage of Content Types is reusable metadata in SharePoint. At times, You may need to get content type id by name in order to  assign the content type to lists and libraries programmatically. Lets get content type id in SharePoint 2013 using PowerShell.

How to find content type id in SharePoint List?
To get content type id from SharePoint interface:
  • Open your SharePoint List in browser >> click on "List Settings" from the List tab of the Ribbon
  • In the List Settings page click on your target content type under "Content types" - Assuming content types are enabled already.
  • Now, You'll see the ID of the content type in the URL.The last part is the Content Type Id. E.g. http://intranet.crescent.com/_layouts/15/ManageContentType.aspx?List=%7BEE1EA017%2DD347%2D49E6%2D9FE2%2D2CA7D1CB7B57%7D&ctype=0x01160074E6A09BFE52244F8ECB851FF74077FCsharepoint 2013 powershell get content type id
Same procedure applies for Site content Types as well. Go to Site settings >> Site Content Types >> Pick your content type >> The URL will have "Ctype" parameter with the content type ID of the respective content type.

SharePoint 2013 PowerShell to get content type id:
Here is the SharePoint PowerShell to find content type by id.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="http://intranet.crescent.com"
$ListName="Projects"
$ContentTypeName="Contact Project"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists.TryGetList($ListName)
#Get the content Type from its name
$ContentType = $List.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID 

Similarly, to get the site content type id in SharePoint 2013 using Powershell, use:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="http://intranet.crescent.com"
$ContentTypeName="Crescent Configuration Entry"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
#Get the content Type from its name
$ContentType = $Web.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID
How to get a content Type by ID?
$CT = $Web.ContentTypes | Where {$_.ID -eq "0x01005B3FBCA1E5314D57B4198D54F9F9B9CD"}

Tags: sharepoint powershell find content type by id,  find content type id sharepoint 2013, get content type id sharepoint 2013 powershell, how to get content type id from sharepoint, sharepoint get content type id programmatically

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


Monday, October 10, 2016

Get All Site Collections in a Web Applications using PowerShell

To get all site collections in web application, from SharePoint central Admin, follow these steps:
  • Go to SharePoint Central Admin Site >> Application Management 
  • Click on "View all site collections" link under Site Collections Group. Select your web application. This page lists all site collections in the selected web application.
    sharepoint get all site collections in web application
Get all site collections in web application using PowerShell:
Here is the PowerShell to list all site collections in web application.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set the Web application URL
$WebAppURL="http://intranet.crescent.com"

#Get the Web Application        
$WebApp = Get-SPWebApplication $WebAppURL

#Get all Site collections from the web application
$SitesCollection  = $WebApp.Sites

#Enumerate all site collections in the web application
Foreach($Site in $SitesCollection)
{
    #Get Site Collection URL, Owner, Content Database Details
    Write-host $Site.URL
}

While the above code written in classic manner, you can use PowerShell one-liner to get list of all site collections in web application:
Get-SPWebApplication "http://intranet.crescent.com" | Get-SPSite | Select URL

PowerShell to get all site collections in a web application:
This time, lets use PowerShell expressions to dig into site collection properties, say: Site Name, content database, etc.
Get-SPWebApplication "http://intranet.crescent.com" | Get-SPSite | Select URL,@{Name="Site Name"; Expression={$_.RootWeb.Title}},Owner 

How to get all site collections in a web application and Export to CSV
How about get all site collections in a web application using PowerShell and Export to CSV?
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Web application URL and CSV File location Variables
$WebAppURL="http://intranet.crescent.com"
$CSVFile="C:\SitesList.csv"

#Get list of site collections in a web application powershell
 Get-SPWebApplication $WebAppURL | Get-SPSite | ForEach-Object {
 New-Object -TypeName PSObject -Property @{
             SiteName = $_.RootWeb.Title
             Url = $_.Url
             DatabaseName = $_.ContentDatabase.Name }
} | Export-CSV $CSVFile -NoTypeInformation
This Script gets all site collections from the given web application and exports the site collection data to CSV
how to get all site collections in a web application using powershell

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


Add-Remove User to SharePoint Multi-Valued People Picker Field using PowerShell

Requirement: 
We've a SharePoint list called "Projects" with 1000's of items. The list has a field called "Team Members" which allows multiple user values. We often get a requirement to either add or remove a particular user to all items or specific items filtered by other columns in the list.

Solution: Adding-removing user from multiple items in a bulk can be achieved with PowerShell. Lets use PowerShell to add or remove user from SharePoint people picker (person or group) field value.
powershell to add remove user to people picker column value in sharepoint


PowerShell to Add new user to Person or Group Field:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration parameters
$SiteURL = "http://portal.crescent.com/projects/"
$ListName = "Projects"                
$FieldName= "TeamMembers"
$UserToAdd="Crescent\Sam"

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

#Item Ids to update
$IDColl= @(4,5,7,14,55,169,258,260,261)

#Iterate through each item
foreach($ItemID in $IDColl)
{
    #Get the Item
    $Item = $List.GetItembyID($ItemID)
 Write-Host "Processing: "$item["ProjectName"]
    
    #Get Existing field value
    $MultiUserCollection = [Microsoft.SharePoint.SPFieldUserValueCollection]$item[$FieldName]
          
    #Prepre the user to Add
    $User = $Web.EnsureUser($UserToAdd)

 #Add new user to the collection
 $NewUser = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $User.ID,$User.Name)
 $MultiUserCollection.Add($NewUser)

 #Update the field value
 $item[$FieldName] = $MultiUserCollection
 $item.update()   
 
 write-host "Team Member Added!"     
}

PowerShell to remove user from Multi-user People Picker field:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration parameters
$SiteURL = "http://portal.crescent.com/projects/"
$ListName = "Projects"                
$FieldName= "TeamMembers"
$UserToRemove="Crescent\Sam"

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

$IDColl= @(184,259,281,282,306,318,331,378,404,410)
foreach($ItemID in $IDColl)
{
        #Get the Item
        $Item = $List.GetItembyID($ItemID)
        Write-Host "Processing: "$item["ProjectName"]
        
        #Get Existing field value
        $MultiUserCollection = [Microsoft.SharePoint.SPFieldUserValueCollection]$item[$FieldName]
        $NewUserCollection = new-object Microsoft.SharePoint.SPFieldUserValueCollection
       
        #Prepre the user to remove
        $User = $Web.EnsureUser($UserToRemove)
  
        #Create a new collection - exclude user to remove      
        Foreach($MultiUser in $MultiUserCollection)
        {
            if($MultiUser.User.LoginName -ne $User.LoginName)
            {
                #Add user to new collection
                $NewUser = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $MultiUser.User.ID,$MultiUser.User.Name)
                $NewUserCollection.Add($NewUser)
            }
         }
        #Update the list item 
        $item[$FieldName] = $NewUserCollection
        $item.update()   
  
        write-host "User Removed From Existing People Picker field Value!"     
 }


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


Saturday, October 8, 2016

SharePoint Online: How to Check in a Document using PowerShell CSOM

Check out-Check in feature in SharePoint avoids conflicts in typical collaboration environments, where multiple users may try to edit the same document at the same time. You must check in the document back in order to make the changes available to all other users, Even if the document is saved.

How to Check-in a document in SharePoint online?
To check in a checked out file, follow these steps in SharePoint online.
  • Navigate to the document library where the checked out file is saved. Select the document(s) to Check in. 
  •  From the ribbon, click the Files tab, click on "Check In" from the "Open & Check Out" group.
  • In the Check In dialog box, click No for "keep the file checked out after checking it in" option.
  • Click OK.
If you Checking in a document but retain it to checkout, other users get to see your latest changes while you may continue to work on the rest of the changes to your document.
how to checkin a document in sharepoint online powershell

SharePoint online PowerShell to check in a document
Here is the PowerShell way of check in file in SharePoint Online.
#Load SharePoint CSOM 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"
  
#Function to Check if file exists in given URL
Function Checkin-Document($SiteURL, $FileRelativeURL, $Credentials)
{

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    Try {
        #Try to get the File from URL
        $File = $Ctx.web.GetFileByServerRelativeUrl($FileRelativeURL)
        $Ctx.Load($File)
        $Ctx.ExecuteQuery()
        
        #check if the file is checked out
        If($File.CheckOutType -eq "None")
        {
            write-host "Document is not checked out Already!" -f Red
            break
        }
        #Checkin the document
        $File.CheckIn("",[Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
        #Checkin Types: MajorCheckIn,MinorCheckIn,OverwriteCheckIn

        $Ctx.ExecuteQuery()

        write-host "Document has been checked-in successfully!" -f Green
    }
    Catch {
        write-host -f Red "Error checking-in Document!" $_.Exception.Message
    }
}

#Set Variables for Site URL, List Name and Column Name
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$FileRelativeURL="/sites/Sales/Shared%20Documents/Legal%20Template.xssn"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function to Checkin file
Checkin-Document -SiteURL $SiteURL -FileRelativeURL $FileRelativeURL -Credentials $Cred

The above script gets the file from URL. Alternatively, you can get file from Item ID and check in. Here is an another example.
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL, Library Name and Item ID
$SiteURL= "https://abraaj.sharepoint.com/sites/sales/"
$LibraryName="Documents"
$ItemID="4"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

#Get the web, List, Item adn File
$Web=$Ctx.Web
$List=$web.Lists.GetByTitle($LibraryName)
$Item=$list.GetItemById($ItemID)
$File=$Item.File

#Get the File to context
$Ctx.Load($File)
$Ctx.ExecuteQuery()
        
#check if the file is checked out
If($File.CheckOutType -eq "None")
{
    write-host "Document is not checked out Already!" -f Red
}
else
{
    #Check in the file
    $File.CheckIn("Checked-in from PowerShell",[Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
    $Ctx.ExecuteQuery()
    
    write-host "Document has been checked-in successfully!" -f Green
}


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


SharePoint Online: How to Checkout a Document using Powershell CSOM

Checking out a document in SharePoint ensures that you are the only one making edits to it. The purpose of checkout is to prevent conflicts in a collaboration environment where multiple people may try to edit the same document or list item at the same time. So, When a file is checked out to you, you are the only one allowed making changes to it. The file will remain locked until you release it.

When you're finished making edits, check in the document so that other users can view the changes you made. The option of "Require checkout" can be turned ON or OFF from document library settings.

How to Check out a document?
  • Navigate to the document library in your SharePoint or SharePoint online site. Select the document which you would like to checkout. 
  • On the ribbon, click on Files tab, Click on "Check Out" button. (or you can checkout from the item's context menu)
  • Once the document is checked out, you'll get a tiny outward-pointing  green arrow, in the document icon.
how to checkout a file in sharepoint online powershell


PowerShell script to checkout a document in SharePoint online:
#Load SharePoint CSOM 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"
  
#Function to Check if file exists in given URL
Function Checkout-Document($SiteURL, $FileRelativeURL, $Credentials)
{

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    Try {
        #Try to get the File from URL
        $File = $Ctx.web.GetFileByServerRelativeUrl($FileRelativeURL)
        $Ctx.Load($File)
        $Ctx.ExecuteQuery()
        
        #check if the file is already checked out
        If($File.CheckOutType -ne "None")
        {
            write-host "File is already checked-out!" -f Yellow
            break
        }
        #Checkout the document
        $File.CheckOut()
        $Ctx.ExecuteQuery()

        write-host "Document has been checked-out successfully!" -f Green
    }
    Catch {
        write-host -f Red "Error checking out Document!" + $_.Exception.Message
    }    
}

#Set Variables for Site URL, List Name and Column Name
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$FileRelativeURL="/sites/Sales/Shared%20Documents/Legal%20Template.xsn"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function to Checkout file
Checkout-Document -SiteURL $SiteURL -FileRelativeURL $FileRelativeURL -Credentials $Cred 

SharePoint Online: Checkout Document using PowerShell CSOM:
Alternatively, instead of document URL, some times you may have to checkout from the Item ID. Here is the script to checkout a document from the item id.
#Load SharePoint CSOM 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"
  
#Set Variables for Site URL, Library Name and Item ID
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$LibraryName="Documents"
$ItemID="4"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

#Get the web, List, Item adn File
$Web=$Ctx.Web
$List=$web.Lists.GetByTitle($LibraryName)
$Item=$list.GetItemById($ItemID)
$File=$Item.File

#Check out the file
$File.CheckOut()
$Ctx.ExecuteQuery()


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


SharePoint Online: Check if File Exists in Document Library using PowerShell CSOM

Requirement: Check if a file exists in SharePoint online document library using PowerShell CSOM.

PowerShell to check if a file exists in SharePoint online document library:
Lets check if file exists in SharePoint document library with PowerShell.
#Load SharePoint CSOM 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"
  
#Function to Check if file exists in given URL
Function Check-FileExists($SiteURL, $FileRelativeURL, $Credentials)
{
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    Try {
        #Try to get the File from URL
        $File = $Ctx.web.GetFileByServerRelativeUrl($FileRelativeURL)
        $Ctx.Load($File)
        $Ctx.ExecuteQuery()
        Return $True
    }
    Catch {
        Return $False
    }    
}

#Set Variables for Site URL, List Name and Column Name
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$FileRelativeURL="/sites/Sales/TeamDocuments/LegalTemplate.docx"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function to Check Column Exists in given list
$FileExists = Check-FileExists -SiteURL $SiteURL -FileRelativeURL $FileRelativeURL -Credentials $Cred

if($FileExists) {
    write-host "File Exists in the Given URL!" -f Green
    #Proceed with your script
 }
 else {
    write-host "File Doesn't Exists in the given URL!" -f Red
 }
Tags: check if file exists in sharepoint document library csom powershell, how to check file exists in sharepoint library, sharepoint check file exists document library, sharepoint csom check file exists, sharepoint powershell check if file exists in library

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


SharePoint Online: Check If Field Exists in List using PowerShell

Requirement:
PowerShell to check if a field exists in list in SharePoint online.

SharePoint Online - PowerShell to check if a Column exists in List
#Load SharePoint CSOM 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"
  
#Function to Check if a column exists in a List
Function Check-ColumnExists($SiteURL, $ListName, $FieldName, $Credentials)
{
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Retrive all Fields from the list
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Fields = $List.Fields
    $Ctx.Load($List)
    $Ctx.Load($Fields)
    $Ctx.ExecuteQuery()

    #Check if the given field name 
    $Field = $Fields | where{$_.Title -eq $FieldName}
    if($Field)  { return $true } else { return $false}
}

#Set Variables for Site URL, List Name and Column Name
$URL= "https://crescent.sharepoint.com/sites/sales/"
$List="Project Documents"
$Field="Department" #Display Name

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function to Check Column Exists in given list
$ColumnExists = Check-ColumnExists -SiteURL $URL -ListName $List -FieldName $Field -Credentials $Cred

if($ColumnExists) {
    write-host "Column Exists in Given List!" -f Green
    #Proceed with your script
 }
 else {
    write-host "Column Doesn't Exists in given List!" -f 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: Check if List Exists using PowerShell

Requirement:
Check if a particular list exists in a given SharePoint online site using PowerShell csom script.

PowerShell Script to check if List Exists in SharePoint Online:
#Load SharePoint CSOM 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"
  
#Custom Function to Check if Site Collection Exists in Given URL
Function Check-ListExists($SiteURL, $ListName, $Credentials)
{
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    Try {
            $List = $Ctx.Web.Lists.GetByTitle($ListName)
            $Ctx.Load($List)
            $Ctx.ExecuteQuery()
            Return $True
        }
    Catch [Exception] {
      Write-host $_.Exception.Message -f Red
      Return $False
     }
}

#Set Variables for Site URL and List Name
$URL= "https://crescent.sharepoint.com/sites/sales/"
$List="Documents"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function to Check List Exists in given web  
$ListExists = Check-ListExists -SiteURL $URL -ListName $List -Credentials $Cred

if($ListExists) {
    write-host "List Exists in Given Site!!" -f Green
    #Proceed with your script
 }
 else {
    write-host "List Doesn't Exists on given web!" -f 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: Check if Site Collection, Subsite Exists using PowerShell CSOM

Requirement: Check if site or site collection exists in SharePoint online using PowerShell CSOM.

SharePoint Online PowerShell-CSOM to check if site or site collection exists in given URL:
This PowerShell script checks if site collection exists in the given URL.

#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"
  
#Custom Function to Check if Site Collection Exists in Given URL
Function Check-SiteExists($SiteURL, $Credentials)
{
    #Setup context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    $Web = $Ctx.Web
    $Ctx.Load($web)
    
    Try {
            $Ctx.ExecuteQuery()
            Return $True
        }
    Catch [Exception] {
      Write-host $_.Exception.Message -f Red
      Return $False
     }        
}

#Variable for Site collection URL
$URL= "https://crescent.sharepoint.com/sites/sales/"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
  
$SiteExists = Check-SiteExists -SiteURL $URL -Credentials $Cred

#Call the function to check site exists
if($SiteExists -eq $True)
 {
    write-host "Given Site Collection Exists!" -f Green
    #Proceed with your script
 }
 else
 {
    write-host "Site Collection doesn't Exists on given URL!" -f Red
 }
Please note, the function Check-SiteExists may return false in case of any network related issue or authentication failures.

My another server side script to Check if site collection or subsite exists in SharePoint using PowerShell in SharePoint on-premises.

Tags: sharepoint check site exists, sharepoint check site collection exists, powershell sharepoint check site exists, sharepoint csom check if site exists, sharepoint check if url valid, sharepoint powershell check if site exists, check if subsite exists sharepoint powershell csom

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...