When
the videos in this series were recorded, Peter Kalmström
used an older version of the PnP module, called
SharePointPnPPowerShellOnline, which built on PowerShell version 5. At that time,
the PowerShell scripts were created in the app PowerShell
ISE.
Since then, Microsoft has introduced the more powerful,
cross-platform version 7 of PowerShell and the module PnP.PowerShell. It is recommended to work with this module in
the source-code editor Visual Studio Code (which is not
the same as Visual Studio).
Once VS Code and its PowerShell extension has been installed
and registered, the code that is shown in this demo series
is generally written in the same way as before.
Below are the steps to install PowerShell version 7 and
VS Code, to set up Visual Studio Code for PowerShell scripting
and to connect to SharePoint Online.
Note that step 9 must be performed by a Global Administrator,
as permissions are set on behalf of the organization.
Open the Extensions view, type PowerShell and select
the PowerShell extension.
Create a new .ps1 file.
Register the application. Give it a name and enter
your tenant name: Register-PnPEntraIDAppForInteractiveLogin
-ApplicationName"YOUR
NAME" -Tenant
TENANTNAME.onmicrosoft.com-Interactive
Log in and Consent to and Accept the permissions.
Note the Client ID that you get in the VS Code Terminal.
It is needed to connect to SharePoint. The ID can also
be found at Entra ID >Identity >Applications >App
Registrations.
Import the PnP module:
Import-ModulePnP.PowerShell
To work with a SharePoint Online site, connect to
the site using Interactive mode and your Client ID:
Connect-PnPOnline
-UrlURL TO
THE SITE-Interactive-ClientIdYOUR
ID
Now you can develop scripts and run PowerShell 7
code in VS Code in the same way as in PowerShell ISE.
Peter shows the new way to connect in the first demo
below. The process to install PowerShell and VS Code and
set it up for SharePoint Online modification is also
described in detail in the book
PowerShell with SharePoint from Scratch.
If you prefer using the Windows PowerShell ISE, it is still
available for Windows, and Microsoft have no plans to remove
it. However, the ISE only works with PowerShell 5.1 and
older, and even if Microsoft will continue to support ISE
for security and high-priority servicing fixes, it is no
longer in active feature development. Peter shows the steps
forPowerShell V5 and PowerShell ISE in the demo below.
In the
next article, we will show how you can avoid the login
screen when you often use PowerShell with SharePoint. If
you don't need that possibility now, you can go directly
to
the first article about app creation.