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

Micki 1 Reputation point
2020-10-16T10:01:23.82+00:00

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 ?

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,605 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,512 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,449 questions
{count} votes

2 answers

Sort by: Most helpful
  1. aperally 6 Reputation points
    2020-10-16T15:44:48.967+00:00

    you can store the credential in credential manager on Windows and then provide them when you connect

    Connect-PnPOnline -Url http://yourlocalserver -Credentials 'O365Creds'  
    

    https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

    1 person found this answer helpful.
    0 comments No comments

  2. Echo Du_MSFT 17,156 Reputation points
    2020-10-19T02:47:04.51+00:00

    @Micki

    You could refer to the following script to connect to SharePoint sites :

    $username = " ****** "  
    #<the full email address of a SharePoint administrator account, example: jdoe@contosotoycompany.onmicrosoft.com>  
    $siteUrl = "https://sp/sites/test"  
    $FileRelativeURL = "/.../.../Test.docx"  
    $DownloadPath = "C:\Temp"  
    Try {  
         #Connect to PNP Online  
         $credential = Get-Credential -UserName $username -Message "Type the password:"  
         Connect-PnPOnline -Url $siteUrl -Credentials $credential          
         # download file   
         Get-PnPFile -Url $FileRelativeURL -Path $DownloadPath -AsFile  
     }  
     catch {  
         write-host "Error: $($_.Exception.Message)" -foregroundcolor Red  
     }  
    

    You could refer to this article Connect-PnPOnline to learning more command to connect to SharePoint.

    Thanks,
    Echo Du

    ==========

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.