简体   繁体   中英

Powershell PnP - login to Sharepoint online and download file

I am trying to login to Sharepoint Online with PnP. The thing is once I use credentials it prompts me to select windows credentials and while I try to use weblogin:

Connect-PnPOnline -Url "https://somesite.sharepoint.com" -UseWebLogin

It automatically tries to log me in with my currrent Windows User.

What I try to achieve is authenticate with some user/password I provide in the code and download file from Sharepoint in the background.

Is there any way to achieve it with PnP?

Please try following code

# Variable - Change the parameter as it need  
$O365ServiceAccount = "test@abc.com"  
$O365ServiceAccountPwd = "Test123$"  
$SharePointSiteURL = "https://abc.sharepoint.com/sites/Test"  
# Change this SharePoint Site URL  
$SharedDriveFolderPath = "C:\Users\kumavini\Documents\FolderA"  
# Change this Network Folder path  
$SharePointFolderPath = "Shared Documents/FolderA"  
# Change the Document Library and Folder path  
#Ends[SecureString] $SecurePass = ConvertTo - SecureString $O365ServiceAccountPwd - AsPlainText - Force[System.Management.Automation.PSCredential] $PSCredentials = New - Object System.Management.Automation.PSCredential($O365ServiceAccount, $SecurePass)  
#Connecting to SharePoint site  
Connect - PnPOnline - Url $SharePointSiteURL - Credentials $PSCredentials  
$Files = Get - PnPFolderItem - FolderSiteRelativeUrl $SharePointFolderPath - ItemType File  
foreach($File in $Files) {  
    Get - PnPFile - Url $File.ServerRelativeUrl - Path $SharedDriveFolderPath - FileName $File.Name - AsFile  
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM