Run any version of PNP without Installation

Summary

When testing scripts, you may need functionality in a newer version of PNP than what you have installed on your device. Also, there may be a need to run an older version, if your script is using functions or parameters that were deprecated in newer versions.  This blog will walk you through the process of using any version of PNP without installation.

Steps

1. Determine which version of PNP is needed and the PowerShell requirements of that version.

For example:

  • PnP.PowerShell 1.1.0 requires PS 5.1 or higher.
  • PNP.PowerShell 2.0 requires PS 7.2 or higher.
  • PnP.PowerShell 3.0 Requires PS 7.4 and higher

2. One you have the requirements down, make sure are using the correct version of PowerShell to load the PnP.PowerShell modules.

Note: PowerShell 5.x comes with Windows. You need to download PowerShell 7.x.

See: Installing PowerShell on Windows – PowerShell | Microsoft Learn

3. Locate the version of PnP.PowerShell you want to test, by visiting the PnP.PowerShell Gallery

https://www.powershellgallery.com/packages/PnP.PowerShell

4. Expand the “File List” and locate the version you want. For this Blog, I will focus on the latest version.

5. After clicking on version 3.1.22-nightly, you will see 4 install options.

  • Install module
  • Install PSResource
  • Azure Automation
  • Manual Download

6. Click on manual download.

7. Now download the raw “nupkg” file.

8. The file “pnp.powershell.3.1.22-nightly.nupkg” will be downloaded.

9. Move the file to a new empty folder.

10. For this example, I’m using C:\temp\pnp.powershell.3.1.22

11. Open the folder and rename your file with a .zip extension.

Note: My name file name is “pnp.powershell.3.1.22-nightly.zip

12. Extract the folder into your preferred location. For example, I will extract mine too c:\temp\pnp.powershell.3.1.22-nightly.

13. Now open PowerShell 7x as Admin from your device.

Hint:  Search for “PowerShell” in your Start menu.

Note: If you don’t have PowerShell 7 installed, see: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows

14. Change Directory to the folder you extracted PNP.

cd C:\temp\pnp.powershell.3.1.22\pnp.powershell.3.1.22-nightly

15.  Import the PNP Module

import-module -name .\PnP.PowerShell.psd1

16. You may get an error stating the import failed because it’s a nightly build that is not digitally signed.

17. If this occurs, set your execution policy

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

18. Now try importing the module again.

import-module -name .\PnP.PowerShell.psd1

19. Now verify the imported module.

get-module -name “PnP.PowerShell”

Success!  You have loaded the latest version of PNP.

Test running PNP

1. Register a new PNP App to use with interactive mode.

Register-PnPEntraIDAppForInteractiveLogin -ApplicationName “PNPAPP” -Tenant m365cpi13246019.onmicrosoft.com

2. After running this, you may be a prompt to consent to the permissions.

Example:

3. This new application will be created in Entra App Registrations.

Example:

4. Notice the default permissions created after executing the register command

5. Let’s test it using the new Client ID.

connect-pnponline -url “https://m365cpi13246019-admin.sharepoint.com” -clientId ‘1e892341-f9cd-4c54-82d6-0fc3287954cf’-Interactive

6. You will be prompted for a username and password. Ensure to use sure your SharePoint Admin Account here.

7. Now you are free to use PNP commands that are included with the targeted version of PNP, without installing the module.

Conclusion:

In summary, following the outlined steps will enable you to run any version of PNP without installation. By carefully adhering to each step, you can ensure a smooth and efficient process, ultimately achieving the desired outcome. Remember to double-check each step for accuracy and completeness to avoid any potential issues.

Leave a Reply