Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Install Module command not failing but not installing module

I am trying to install the PnP online commands for SharePoint onto my PowerShell however the following command doesn't seem to work;

Install-Module -name SharePointPnPPowerShellOnline -scope CurrentUser

The command seems to run through fine with no errors appearing but when I try to run Commands which should have been installed I get an error saying the commands can not be found.

connect-pnponline : The term 'connect-pnponline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of        
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ connect-pnponline
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (connect-pnponline:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I have had a look at all the module folders and the module is not in any of them. I have compared my environment paths with a coworker who has this working and they are the same.

Does anyone know what might be causing this?

like image 902
Ross.Muszynski Avatar asked Aug 03 '26 13:08

Ross.Muszynski


2 Answers

This was caused by by modules being stored on OneDrive. By default my module path was set to "%USERPROFILE%\Documents\WindowsPowerShell\Modules" but since i had OneDrive installed my path changed to "%USERPROFILE%\OneDrive\Documents\WindowsPowerShell\Modules".

To resolve this issue I went to Documents>Windows Powershell>Modules and copied the link. Then, via the Start' menu, I went to 'Edit the system environment variables'>advanced>Environment Variables, highlighted PSModulePath and clicked Edit. Once in this window I clicked New and pasted the link I found above. This resolved the problem I was experiencing.

like image 165
Ross.Muszynski Avatar answered Aug 05 '26 19:08

Ross.Muszynski


The module probably isn't imported. You should be able to execute
Import-Module SharePointPnPPowerShellOnline which should either import your module, or give you an error if it can't be imported for some reason.

To tackle the non-autoloading issue, check the following:

  • Check that you're setting $PSModuleAutoLoadingPreference and that it's not set to None or 0
  • Cmdlets which make use of a PowerShell provider do not get automatically imported
    • SharePointPnPPowerShellOnline implements a SharePoint provider so I'd wager this is the case.
like image 28
Bender the Greatest Avatar answered Aug 05 '26 18:08

Bender the Greatest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!