Maintaining Multiple Connections to PnPONline

Silver Contributor

I'm trying to create a script that will copy users from SPO Groups to Office/Unified groups. I think that I should be able to do this by using  Connect-pnpOnline -graph  and Connect-PnPOnline -Url, but I'm not sure how to maintain 2 separate connections in the same script. Can someone point in the right direction?

 

@Erwin van Hunen

1 Reply

I think you need to use the ReturnConnection parameter of the Connect-PnPOnline command.

Sample code would be something like :

$connection1 = Connect-PnPOnline -Url "someurl" -ReturnConnection

$connection2 = Connect-PnPOnline -Graph -ReturnConnection

Get-PnPUser -Identity i:0#.f|membership|user@tenant.onmicrosoft.com -Connection $connection1

New-PnPUser -LoginName "<loginName>" -Connection $connection2

Connect-PnPOnline