If you want to do a connection to SharePoint Online with a PowerShell script. You will need to make a connecting user and a certificate for logon. The legacy function with plain text user/password does not work anymore.
The PowerShell CMD-let SharePoint Online PnP has been beprecated and is replaced with PnP PowerShell. Do the following to confirm right installed CMD-let
To check if you have the right version of PowerShell. You will need at least PowerShell 7.3
1 $PSVersionTable.PSVersion
Get all installed SharePoint Online PnP PowerShell Modules
1 Get-module
-ListAvailable
*pnp*
If both or PnP Classic is installed
1 Uninstall-Module PnP.PowerShell
-AllVersions
-Confirm:$False
2 Uninstall-Module SharePointPnPPowerShellOnline
-AllVersions
-Confirm:$False
Some versions of PowerShell need to change the TLS to version 1.2 for uninstall and install to work
1 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install the latest version of PnP.PowerShell. Choose install option Yes to All
1 Set-ExecutionPolicy RemoteSigned
2 Install-Module PnP.PowerShell
You have now installed the new Module
To make a connection to SharePoint Online you will need a global account to your Tenant and some information.
Make a folder for your certs at the local computer “c:\mycertificates”. Do not use spaces or local characters for the folder name. Register the account.
$result = Register-PnPEntraIDApp -ApplicationName “[MySharePointAppName]” -Tenant [TenantName].onmicrosoft.com -OutPath c:\mycertificates -Interactive
$result
Sign in with your Admin account and the script will return a client ID on success. Store the client ID for feature use. You will receive two certificates in your certificate folder.
To make a connection to SharePoint
Connect-PnPOnline [TenantName].sharepoint.com/sites/[folder] -ClientId [ClientIDNo] -Tenant [TenantName].onmicrosoft.com -CertificatePath “C:\mycertificates\[MySharePointAppName].pfx”