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 ar...
sickaroll
Aug 22, 2022Brass 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 $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.")
)