Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run script - complains that Connect-PnPOnline is not recognised, even though it has been verified earlier in the script #83

Closed
martinharris362 opened this issue Dec 5, 2023 · 8 comments
Assignees

Comments

@martinharris362
Copy link

martinharris362 commented Dec 5, 2023

Here is the output from the script. It says PnP Powershell is installed

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
message. Do you want to run C:\365inspect\365Inspect-main\365Inspect.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): R

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
message. Do you want to run C:\365inspect\365Inspect-main\Write-ErrorLog.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): R
Verifying environment.

Environment is 7.4.0
[+] PowerShellGet is installed.
Importing PowerShellGet
Environment is 7.4.0
[+] ExchangeOnlineManagement is installed.
Inporting ExchangeOnlineManagement
Importing Microsoft.Graph
Environment is 7.4.0
[+] Microsoft.Graph is installed.
Inporting ExchangeOnlineManagement
Importing Microsoft.Graph
Environment is 7.4.0
[+] PnP.PowerShell is installed.
Environment is 7.4.0
[+] MicrosoftTeams is installed.
Importing MicrosoftTeams
Connecting to Microsoft Graph
Welcome to Microsoft Graph!

Connected via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e
Readme: https://aka.ms/graph/sdk/powershell
SDK Docs: https://aka.ms/graph/sdk/powershell/docs
API Docs: https://aka.ms/graph/docs

NOTE: You can use the -NoWelcome parameter to suppress this message.

Connected via Graph to xxxxxxxxxxx
Connecting to Security and Compliance Center


We have made updates to move the SCC admin experience to REST-based APIs. In doing so, we will be deprecating the legacy Remote PowerShell (RPS) protocol starting July 15, 2023.

Benefits of REST-based cmdlets: improved security, WinRM no longer required for client-server communication, improved error handling.

The REST API has the same cmdlets available and feature parity with RPS(V1) cmdlets, so existing scripts and processes don't need to be updated. Simply using the new module will ensure REST is used rather than RPS.

For more information, go to https://aka.ms/exov3-module

Connecting to Exchange Online
Connecting to SharePoint Service
Connecting to SharePoint Service Failed.
Write-Error: C:\365inspect\365Inspect-main\365Inspect.ps1:387
Line |
387 | Connect-Services
| ~~~~~~~~~~~~~~~~
| The term 'Connect-PnPOnline' is not recognized as a name of a cmdlet, function, script file, or executable
| program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
| again.
PS C:\365inspect\365Inspect-main>

@ThoughtContagion
Copy link
Collaborator

Do you see the PnP. PowerShell module when you run this command?

Get-Module -ListAvailable | Where-Object {$_.Name -eq 'PnP.PowerShell'}

@ThoughtContagion ThoughtContagion self-assigned this Dec 5, 2023
@martinharris362
Copy link
Author

No it comes back blank. Even though I have installed it (several times)

@martinharris362
Copy link
Author

martinharris362 commented Dec 5, 2023

Installed again and now shows

ModuleType Version PreRelease Name PSEdition ExportedCommands


Manifest 2.2.0 PnP.PowerShell

but still getting this

Connecting to Exchange Online
Connecting to SharePoint Service
Connecting to SharePoint Service Failed.
Write-Error: C:\365inspect\365Inspect-main\365Inspect.ps1:387
Line |
387 | Connect-Services
| ~~~~~~~~~~~~~~~~
| Could not load file or assembly 'Microsoft.Identity.Client, Version=4.50.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)

@ThoughtContagion
Copy link
Collaborator

I am able to replicate that issue. We will work on a fix.

We can confirm that using PowerShell 5.1 (Windows PowerShell) and PnP.PowerShell version 1.12.0 works as expected.

We do also see several open and unresolved issues where this error is thrown in PowerShell 7+ using the PnP.PowerShell version 2+

@ThoughtContagion
Copy link
Collaborator

We were able to resolve this issue.

The resolution was to forcefully remove the existing PnP.PowerShell module (in our case, this meant opening Explorer and navigating to C:\Users\User\Documents\PowerShell\Module\PnP.PowerShell and deleting the folder named 2.x).
You will need to close all instances of pwsh.exe - any open windows, VS Code if it is open, etc.
Once the module has been purged, reinstalling the module with the CurrentUser Scope allowed us to progress past the authentication screen without errors and run the assessment tool.

Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force

@martinharris362
Copy link
Author

Unfortunately still no joy. I'm getting a different error now regarding MS Identity client, which I have also freshly installed in current user scope

Environment is 7.4.0
[+] PowerShellGet is installed.
Importing PowerShellGet
Environment is 7.4.0
[+] ExchangeOnlineManagement is installed.
Inporting ExchangeOnlineManagement
Importing Microsoft.Graph
Environment is 7.4.0
[+] Microsoft.Graph is installed.
Inporting ExchangeOnlineManagement
Importing Microsoft.Graph
Get-Package: No match was found for the specified search criteria and module names 'PnP.PowerShell'.
InvalidArgument: C:\365inspect\365Inspect-main\365Inspect.ps1:269
Line |
269 | $installedVersion = [Version](((Get-InstalledModule -Name $mo …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot convert value "" to type "System.Version". Error: "Version string portion was too short or too long.
| (Parameter 'input')"
Environment is 7.4.0
[+] PnP.PowerShell is installed.
Environment is 7.4.0
[+] MicrosoftTeams is installed.
Importing MicrosoftTeams
Connecting to Microsoft Graph
Welcome to Microsoft Graph!

Connected via delegated access using 14d82eec-204b-4c2f-b7e8-296a70dab67e
Readme: https://aka.ms/graph/sdk/powershell
SDK Docs: https://aka.ms/graph/sdk/powershell/docs
API Docs: https://aka.ms/graph/docs

NOTE: You can use the -NoWelcome parameter to suppress this message.

Connected via Graph to xxxxxxxxxxxxxxx
Connecting to Security and Compliance Center


We have made updates to move the SCC admin experience to REST-based APIs. In doing so, we will be deprecating the legacy Remote PowerShell (RPS) protocol starting July 15, 2023.

Benefits of REST-based cmdlets: improved security, WinRM no longer required for client-server communication, improved error handling.

The REST API has the same cmdlets available and feature parity with RPS(V1) cmdlets, so existing scripts and processes don't need to be updated. Simply using the new module will ensure REST is used rather than RPS.

For more information, go to https://aka.ms/exov3-module

Connecting to Exchange Online
Connecting to SharePoint Service
Connecting to SharePoint Service Failed.
Write-Error: C:\365inspect\365Inspect-main\365Inspect.ps1:387
Line |
387 | Connect-Services
| ~~~~~~~~~~~~~~~~
| Could not load file or assembly 'Microsoft.Identity.Client, Version=4.50.0.0, Culture=neutral,
| PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)

@martinharris362
Copy link
Author

Have removed everything and gone back to 5.1 and all good now

@ThoughtContagion
Copy link
Collaborator

We've run into this issue with the MS Identity Client many times. It appears to be related to the various modules dependencies and packaged versions of the client. In some cases a newer version of a module has fixed it, in others we've needed to revert to the last known working versions of several modules.

If it helps, this is the current versioning running on my machine and everything works as expected with the fix listed above.
We do still caution using the tool with PS Core as some functionality will be limited in specific PowerShell modules, but we strive to support it regardless.

image

Thank you for using our tool, we hope it provides you with some valuable insight!
Please do not hesitate to reach back out with any additional issues, questions, or feature requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants