pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
625 stars 328 forks source link

[BUG] Connect-PNPOnline getting stuck connecting and locking up PowerShell #2952

Closed JMyklebust closed 1 year ago

JMyklebust commented 1 year ago

Reporting an Issue or Missing Feature

Using Connect-PNPOnline fails and locks up PowerShell. Connect-PnPOnline -Url $AdminURL -Interactive this command will fail "silently". And by silently I mean it locks up PowerShell and only way to break out is to close the PowerShell instance. There is no output for me to check what is wrong.

Expected behavior

Expecting that the command works properly and connects me to Azure/M365. Or alternatively fails with an error message I can work with.

Actual behavior

As noted above, the command seems to fail/halt with the entire shell getting stuck (break commands do not work). There is indication that -Interactive can solve itself after waiting for 5-10 minutes. However using Certificate authentication has shown to just lock up indefinitly (or at least for several hours...).

Steps to reproduce behavior

Simply calling Connect-PnPOnline -Url $AdminURL -Interactive causes issues. Alternatively using Connect-PnPOnline -ClientID $AppID -Tenant $Tenant -Thumbprint $CertThumbprint -Url $AdminURL for certificate auth.

What is the version of the Cmdlet module you are running?

I have tried on 1.12.0 and 2.0.55-nightly. PowerShell version is 7.3.3. Running on Windows 11 22H2 (Build 22621.1265)

Which operating system/environment are you running PnP PowerShell on?

KoenZomers commented 1 year ago

Hi @JMyklebust this one will be impossible for us to fix without knowing what's going on as for everyone else its working fine. Are you sure there's not somewhere, perhaps on another screen or behind other windows, a login dialog that pops up when you run this? Can you run a network trace using i.e. Fiddler and see what happens over the wire when you're connecting?

veronicageek commented 1 year ago

Closing as no report of such behaviour for this cmdlet.

HiroshiIseki commented 1 year ago

This should not be closed in my opinion. I'm having the same issue , but with version 3.23.2007.1 of SharePointPnPPowerShellOnline this does not happen.

BUG Stuck on connecting to pnponline when clicking form button #1329

haydentrail commented 1 month ago

If anyone is still needing to find a way to get the module working in powershell forms you can create the connection using a runspace.

$syncHash = [hashtable]::Synchronized(@{connection = $null}) $scriptBlock = { import-module "PnP.PowerShell" $syncHash.connection = connect-pnponline -url 'YOURURL' -UseWebLogin -ReturnConnection } $RS = [RunspaceFactory]::CreateRunspace() $RS.ApartmentState = "STA" $RS.ThreadOptions = "ReuseThread" [void]$RS.Open() $RS.SessionStateProxy.SetVariable("syncHash",$syncHash) $psCmd = [PowerShell]::Create($RS) [void]$psCmd.AddScript($scriptblock) [void]$psCmd.Invoke() [void]$psCmd.Dispose()

Then $syncHash.connection will contain your connection object and you can use that to run other pnp commands.