Forum Discussion
Frederick Wilson
Aug 05, 2019Brass Contributor
SharePoint Online Powershell Connection (MFA) inside PS Job
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?
1 Reply
- sickarollBrass Contributor
Use -returnconnection and save the result as something.
$MyWebConnection = connect-pnpOnline -url -interactive -returnconnectionThen you can use the connection switch to 'force' the use of this connection.
$web = get-pnpWeb -connection $MyWebConnectionYou 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.") )