powershell: [BUG] Cannot connect with credentials
Notice
Many bugs reported are actually related to the PnP Framework which is used behind the scenes. Consider carefully where to report an issue:
- Are you using
Invoke-PnPSiteTemplateorGet-PnPSiteTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/pnp/pnpframework/issues. - Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
- If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/powershell/tree/master/src/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/pnp/pnpframework/issues
Reporting an Issue or Missing Feature
Please confirm what it is that your reporting
Expected behavior
Please describe what output you expect to see from the PnP PowerShell Cmdlets Connect-PnPOnline is able to connect to SharePoint Online.
Actual behavior
Please describe what you see instead. Please provide samples of output or screenshots. Returns error… Connect-PnPOnline : The sign-in name or password does not match one in the Microsoft account system.
This would be expected with MFA. However MFA is not enabled here.
Steps to reproduce behavior
Please include complete script or code samples in-line or linked from gists $URL = “https://mysite.sharepoint.com” $login = “user@mysite.com” $pwd = “secure-password”
$pwd = ConvertTo-SecureString $pwd -AsPlainText -Force; $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $login, $pwd
Connect-PnPOnline -Url $url -Credentials $credentials
What is the version of the Cmdlet module you are running?
(you can retrieve this by executing Get-Module -Name "PnP.PowerShell" -ListAvailable)
Which operating system/environment are you running PnP PowerShell on?
- [ X] Windows
- Linux
- MacOS
- Azure Cloud Shell
- Azure Functions
- Other : please specify
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (6 by maintainers)
Hi! When you install the latest SharePointPnPPowerShellOnline and run Connect-PnPOnline you will receive a notification of this fact the we will sunset it. To make sure as many people as possible got the news we have been announcing this several times also in the community calls, but we understand that not everyone has the ability to attend those. As of January 2021 we will not release any new version of SharePointPnPPowerShell2013/2016/2019/Online and focus only on PnP.PowerShell. Maintaining 4 versions was simply too much work given the issues/changes/etc. given the fact that we do this all in our free time.
PnP.PowerShell is the new version (which is works cross-platform and as a result also in the latest versions of Azure Functions etc.), and we do support ‘classic’ auth by means of the -UseWebLogin parameter on Connect-PnPOnline:
Using -UseWebLogin is effectively using cookie based auth. There are some functional limitations to this though. That’s we we recommend other types of authetication.
Due to the fact that Microsoft changed the underlying SDKs and removed the ability to login into SharePoint Online from code by only using credentials we had to also change the approach in PowerShell. This classic auth with username and password is also regarded as ‘legacy’ by Microsoft. New SharePoint Online tenants have this authentication functionality turned of from day 1. (You can enable/disable it with Set-PnPTenant/Set-SPOTenant).
So given that we cannot login with username/password anymore we implemented OAuth based / Azure AD Application ID based authetication. That is the PnP Management Shell application. It’s basically a registration in a tenant we own that has been marked as a multi-tenant application. When using it on PowerShell using the
Register-PnPManagementShellAccesscmdlet you will get a registration in your Azure AD stating that people in your tenant can login using that Application ID (and their username/password) and with the permissions stated for that application. When you run the Register-PnPManagementShellAccess cmdlet you will have to consent to the permissions which is quite a list, basically : access to everything. The user interface will show the list of permissions. However, one still has to login with username/password, using the PnP Management Shell clientid is not enough. The app will basically act as the user logging into to access the resources.As we don’t know about the configuration of your environment, the only other thing I can think of is if you’ve ever registered the PowerShell Gallery as a trusted repository on this machine? Have you succeeded in installing any other module with the
Install-Modulecommand?Like @erwinvanhunen mentionned earlier in the thread, this might seem more like a network issue on your side, or something else missing, but not a PnP PowerShell.
Try to run
Find-PackageProvider -Name "Nuget" -AllVersionshttps://github.com/MicrosoftDocs/PowerShell-Docs/issues/5743Also you can have a look at the following documentation: https://docs.microsoft.com/en-us/powershell/module/powershellget/register-psrepository?view=powershell-7.1 https://docs.microsoft.com/en-us/powershell/module/packagemanagement/install-packageprovider?view=powershell-7.1
If still not working, maybe open an issue on their repo so they can guide you. https://github.com/NuGet/Home
That is 100% correct. Register-PnPManagementShellAccess basically adds a registration to the Azure AD of the tenant for the PnP Management Shell multi-tenant app registration.
Let me start out by setting the tone. It’s “thankful”.
It appears that you are doing everything in your power to spread the information. My issue stems from Google searches that take you to a Microsoft.com page that is outdated. Secondly, the old routines work on my $6/month SharePoint Online site but not my client’s 10,000 user tenet. Again, not your fault.
Thank you for the information!
With “Azure AD Application ID based” it sounds like you grant rights to the “App Registration”. This sounds like the same thing that is going on in the “Register-PnPManagementShellAccess”. Do I have that right? If so, it sounds like using an Application token is the way to go.
In this case it’s important to know the version of PnP PowerShell that you are using as there is a fundamental difference in how the legacy edition (SharePointPnPPowerShellOnline) and the new version (PnP.PowerShell) handle credential based auth. Could you provide that information?
Then try
If you get results for both entries, make sure first to uninstall SharePointPnPPowerShellOnline:
@Geigco - Could you add a title to your issue please? I have tested on PS7 and PowerShell 5.1 with your steps, and I had no issue connecting. So you may have the wrong credentials as the error suggest (my account was not MFA enabled either)
Instead of creating a new object, you could just have a one liner by using
Get-Credential.Also, I would suggest changing your variable
$pwdto something else as it is a reserved/built-in variable.