Update get-credential to support Modern Authentication including MFA
Update get-credential to support Multifactor authentication.
I have 500 SharePoint Online CSOM scripts, and they authenticate with
$SPOcredentials = Get-Credential #-username $username -Message "Please enter the password for $Username to use SPO Cmdlets"
$CSOMCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($SPOcredentials.Username, $SPOcredentials.Password)
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
$Ctx.Credentials = $CSOMCredentials
However, this is not supported when the account requires MFA.
There is a way to establish a context with the PnP AuthenticationManager;
Connect-PnPOnline -returnconnection -useweblogin -url $weburl
$authManager = new-object OfficeDevPnP.Core.AuthenticationManager
$WebCtx = $authManager.GetWebLoginClientContext($WebURL)
but it results in a Ctx with no Credentials parameter, and this causes most of the interesting parts of my scripts to break including all load-csomproperties calls (which you can get around by loading each property tediously one at a time, but crucially kills any CAML queries. Without this I can't load all items in a list, which is vital.
$camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$camlQuery.ListItemCollectionPosition = $position
$camlQuery.ViewXml = $CAMLXML
# Executing the query
$currentCollection = $List.GetItems($camlQuery)
Execute-QueryRespectfully -Ctx $WebCtx -retryAttempts 5
is there a way round this?