Hero Banner

Multi-Factor Authentication (MFA)

Learn and ask questions on how to implement MFA

Reply
Miki_123
Visitor 1

Script for loading files from SharePoint doesn't work on WS 2012 R2 (MFA)

Hi, i have a short ps script to download a file from SharePoint with MFA. 

 

$SiteURL = "https://sharepoint.com/sites/..."
$FileRelativeURL = "/../....docx"
$DownloadPath = "C:\Temp"
 
Try {
    #Connect to PNP Online
    Connect-PnPOnline -Url $SiteURL -UseWebLogin
            
    # download file 
    Get-PnPFile -Url $FileRelativeURL -Path $DownloadPath -AsFile
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

 

it's working fine on my PC, but on Win server 2012 R2 it's still asking to confirm account and loading file.

I am using azure synchronize account. Could someone help to figure it out ?

1 REPLY 1
JanoschUlmer
Microsoft

When the user account has MFA enabled and when the script should run automated, I guess the only option is to use an App (Service principal) with app only permissions: https://www.sharepointdiary.com/2019/03/connect-pnponline-with-appid-and-appsecret.html

Though, I would advice to use certificates, not the app secret in a production environment - but the general approach is quite well described in there.

Kind regards,
Janosch
Get consultations form Technical Presales & Deployment services team via https://aka.ms/technicalservices