pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Add Connection Caching to Connect-PnPOnline #2451

Open sympmarc opened 4 years ago

sympmarc commented 4 years ago

Reporting an Issue or Missing Feature

@ToddKlindt and I have been using the module to do some migrations along with Sharegate's PowerShell module. It's fantastic what we've been able to accomplish, if I may be so bold.

We've built a module (.psm1 file) with a bunch of functions we use to drive the migrations. In many of the functions, the Begin block does connections to common locations. Those connections may have been created already by other functions, but we don't want to make that assumption, because we may call the functions independently. We could build some logic into each function, but it would be redundant. Instead, I've put together a Resolve-Connection function that adds new connections to an array and plucks them back out if they already exist.

Resolve-Connection -Url $Url -Credentials $Credentials

We're calling some of those those functions many times in foreach loops. It would be great if we could cache connections wherever we make them so we wouldn't incur the overhead every time we enter one of the functions.

Thinking it through, it seems it could work by adding a -Cache switch to Connect-PnPOnline, like so:

$newConnection = Connect-PnPOnline -Cache -Url $Url -Credentials $Credentials -ReturnConnection

The -Cache switch would basically be saying: "Save this connection based on the Url and Credentials. If I ask for it again, send me the cached version - I don't need to reconnect."

If the -Cache switch wasn't there, everything would work as it always has.

This may not prove useful to a lot of people, but in situations where we've got lots of iteration, it could potentially decrease execution time considerably, as well as reducing some of the load on the servers.

Which version of the PnP-PowerShell Cmdlets are you using?

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost commented 4 years ago

@sympmarc I agree, that would help a lot when scripting! Lets cross fingers and toes.