Office 365 With PNP PowerShell 2013: Base Cmdlets

This is my third blog post on the topic PnP-PowerShell 2013. In this post I am going to give clear understanding, how to make the connection and close the connection using PnP Base Cmdlets section. 


In the background the “Microsoft.SharePoint.Client.dll” is responsible for get the all results from the SharePoint. 

The value also increase of learning if you already have experience on client object Model.Basic tip from my side please read some information about the client side object model.  

As you may be know the client site object model you can’t get all the data from the server in single request. You need to identify which property you need and just use the load method to load that type of property also you can use the Get-PnpProperties Cmdlet. 

Implementation
The command that I am going to cover as mentioned below. 

These are the most common rest of others not much important in terms of PNP 2013 on premise. The numbers of command are 6.

Sr. No
Command Name
Description as PNP team
1.
Connects to a SharePoint site and creates a context that is required for the other PnP Cmdlets
2.
Returns a Client Side Object Model context
4.
Sets the Client Context to use by the cmdlets
3.
Will populate properties of an object and optionally, if needed, load the value from the server. If one property is specified its value will be returned to the output.
5.
Executes any queued actions / changes on the SharePoint Client Side Object Model Context
6.
Disconnects the context

Connect-PnPOnline: To connect with the SharePoint site there are many methods are available. I recommended, please do check the documentation first.  Depending upon your environment use that type of authentication parameters it could be window, form authentication, O365, app authentication and Azure authentication.'



In On Premise you can use the following two methods mostly.
Case 1 it will show the User name and password prompt. And case 2  the logged machine access to the site then you can use this method with CurrentCredentials switched.

Case 1: Connect-PnPOnline -Url https://contoso.sharepoint.com -Credentials (Get-Credential)
Case 2: Connect-PnPOnline -Url http://yourlocalserver CurrentCredentials
Get-PnPContext :  If you want to save the current context. This command is very handy and it returns the current context. Why you need context it might be the case you need to save the current context. By switch between two sites you need this.

$ctx = Get-PnPContext

Set-PnPContext: It is used to set the connection of the existing saved connection via Get-PnPContext command.
Set-PnPContext -Context <ClientContext>

Get‑PnPProperty:  Load the other properties of the object. By defaults these properties not included in the SharePoint Clinet Site object mode. We need to load the explicitly. Example as mentioned below.
PS:> $web = Get-PnPWeb
PS:> Get-PnPProperty -ClientObject $web -Property Id, Lists
PS:> $web.Lists

Execute-PnPQuery: This will execute the any queued actions/changes on the SharePoint Clint Object model. Also you can retry and wait parameter pass as an optional.
PS:> Execute-PnPQuery -RetryCount 5
PS:> Execute-PnPQuery -RetryWait 10

Disconnect-PnPOnline: Disconnects the context
Disconnect-PnPOnline

I am using all the above methods as we discussed/Covered.

Example Plan: I give you example to connect the site using “Connect‑PnPOnline” and save the context to using “Get‑PnPContext” command. Then use the existing context with the help of “Set‑PnPContext” command and read other properties. And use the  using this command “Execute‑PnPQuery” method to get the some of the important properties. At the end I am close the connect using “Disconnect‑PnPOnline” command. 


Here is the example 1



Here is the example 2


Here is the Example 3




Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

STS CryptographicException Error : Key set does not exist

SharePoint 2016 JavaScript framework