Connect-PnPOnline gets stuck on UseWebLogin - but only sometimes

752 Views Asked by At

We have a script that loops through a CSV input of sites and we don't want to login for every site. Up until a few days ago, it was working fine with the UseWebLogin method, but now we're seeing an error.

The script has an initial connection command: Connect-PnPOnline -Url [TenantHomepage] -UseWebLogin -ReturnConnection

When we run the script, that opens up a browser login. The person running the script enters username, password, MFA token, and selects the stay logged in option.

The script will start looping through the sites on the CSV input and will connect to each of them with essentially the same command: Connect-PnPOnline -Url $siteURL -UseWebLogin -ReturnConnection

A blank browser login will open and close again in about a second because the user is already logged in, the script will connect, and it will successfully perform the actions on that site. It will move on to the next one.

This works fine for the first 2-5 sites in the list but then it will open up a blank login interface and just get stuck there - not logging in automatically and not providing any interface to enter a username or password.

If we stop the script and try running it again, it will get stuck on the first connection. Closing the PowerShell window and reopening it will let us start again.

This was working until a few days ago. It feels like the login is timing out in some way, but I don't know how to work around this.

1

There are 1 best solutions below

0
Muhammad Murad Haider On

Seems like you can use existing connection for the site(s). What are you trying to do after you connect to the site(s). As certain commands allow specifying Connection parameter with pnp command where you can use existing connection variable that was returned from initial Connect-PnPOnline command. e.g.

$folderItems = Get-PnPFolderItem -FolderSiteRelativeUrl $folderServerRelativeUrl -Connection $returnConn

You can try using existing connection like that