Aug 05 2019 10:47 AM
Hello,
I am trying to figure out how to pass a PNP connection to a PowerShell job.
When using Connect-PNPOnline -Url "URL" -UseWebLogin nothing it return so the connection cannot be passed around.
I have some PNP cmdlets running inside Start-Job ScriptBlock.
So instead of running Connect-PNPOnline inside the scriptblock, how can I pass in the connection?
Aug 22 2022 07:05 AM
Use -returnconnection and save the result as something.
$MyWebConnection = connect-pnpOnline -url -interactive -returnconnection
Then you can use the connection switch to 'force' the use of this connection.
$web = get-pnpWeb -connection $MyWebConnection
You can pass them to functions as parameters too:
function Do-StuffInAWeb {
param(
[Parameter(Mandatory=$true)] [PnP.PowerShell.Commands.Base.PnPConnection]$PnPWebConnection,
[Parameter(Mandatory=$true)] [string]$ReportPath =$(throw "-ReportPath parameter is required.")
)