Connect-pnponline: Timeout with certificate based authentication from remote server

von Lachner, Matthias 20 Reputation points
2025-04-22T10:46:24.11+00:00

I uploaded a Certificate which has a private key on my machine which runs the script. It worked out so far, but now it runs into a timeout when I try to execute it remotely (From Server X on the machine where it worked out). My Script currently looks like this:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

pwsh{
import-module PnP.PowerShell
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://myProxy:8080')
#Proxy doesnt need authentication
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

$PWEncoded = "MyPW" |ConvertTo-SecureString -AsPlainText -force

Connect-PnPOnline "https://.sharepoint.com/sites/MySite/"  -ClientId "MyClientID" -Tenant "MyTenant.onmicrosoft.com" -CertificatePath "\\MyServer\D$\SPO\MyCert.pfx" -CertificatePassword $PWEncoded  -Verbose

Add-PnPFile -Path "C:\Temp\MyFile.txt" -newFileName "MyName"  -Folder "MyFolder/Test"

}

When I run this Script remotely from Server X on the very same machine where it was working locally, I get a timeout while connecting with my client ID:

VERBOSE: Cmdlet execution started for Connect-PnPOnline [...] -Verbose VERBOSE: Connecting using Entra ID App-Only using a certificate[0m VERBOSE: Using ClientID MyClientID pwsh.exe : Connect-PnPOnline: In Zeile:1 Zeichen:1

  • pwsh.exe "C:\Users\Me\Desktop\Scripts\pwshTest.ps1"
  • + CategoryInfo : NotSpecified: (Connect-PnPOnline: [:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

[Connect-PnPOnline "https://MyTenant.sharepoint.com/sites/ Request to the endpoint timed out.

I also tried pwsh.exe $ScriptPath but it ended the same way.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,603 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.