SharePoint & PowerShell

PowerShell is a user interface that gives you access to various services of an operating system. A shell can be command-line based, or it can include a graphical user interface (GUI).

SharePoint PowerShell is a shell initially developed by Microsoft for the purposes of task automation and configuration managementPowerShell is now an open source project, and it can be installed on Windows, macOS, and Linux platforms. This shell is based on the .NET framework, and it includes a command-line shell and a scripting language.

Microsoft designed SharePoint PowerShell as a tool that helps you automate and quickly solve a lot of tedious administration tasks. For example, you can use PowerShell to display all the USB devices installed on one or multiple computers in a network, or you can set a time-consuming task to run in the background while you do other work. You can also identify and kill processes that are not responding or filter specific information about computers in a network and export it in HTML format.

PowerShell’s capabilities allow you to simplify and automate tedious and repetitive tasks by creating scripts and combining multiple commands.

Initially, the SharePoint PowerShell was extremely limited in its functionality in association with SharePoint Online environments. With only 30 CMDlets available, there was not much you could easily accomplish without having to write a large amount of CSOM (Client Side Object Model) code. But now there are well over 300 CMDlets available to us through the open source SharePoint PNP PowerShell CMDlets.

A cmdlet is a lightweight command that is used in the Windows PowerShell environment. The Windows PowerShell runtime invokes these cmdlets within the context of automation scripts that are provided at the command line.

So you can easily identify a particular variable within SharePoint and make a change, add, update or delete the item you are designating.

Install PowerShell CMDlets

In order to install the SharePoint PNP CMDlets, open the PowerShell application on your computer as an administrator. Then run the following command. Each line represents the dedicated commands you can install related to SharePoint.

SharePoint Version Command to install
SharePoint Online Install-Module SharePointPnPPowerShellOnline
SharePoint 2019 Install-Module SharePointPnPPowerShell2019
SharePoint 2016 Install-Module SharePointPnPPowerShell2016
SharePoint 2013 Install-Module SharePointPnPPowerShell2013

Updating

Microsoft is constantly updating these CMDlets. So it is good to update them often with the following command within PowerShell:

Update-Module SharePointPnPPowerShell*

Connecting to your site

To use the library you first need to connect to your tenant:

Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)

Or if you have Multi Factor Authentication enabled or if you are using a federated identity provider like AD FS, instead use:

Connect-PnPOnline –Url https://yoursite.sharepoint.com –UseWebLogin

To view all cmdlets, enter:

Get-Command -Module *PnP*

Leave a Reply

Your email address will not be published. Required fields are marked *