![](/img/trans.png)
[英]Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 1-Using PnP.Powershell)
[英]Powershell PnP - login to Sharepoint online and download file
我正在尝试使用 PnP 登录 Sharepoint Online。 问题是,一旦我使用凭据,它就会提示我 select windows 凭据,而我尝试使用 weblogin:
Connect-PnPOnline -Url "https://somesite.sharepoint.com" -UseWebLogin
它会自动尝试使用我当前的 Windows 用户登录。
我试图实现的是使用我在代码中提供的一些用户/密码进行身份验证,并在后台从 Sharepoint 下载文件。
有什么方法可以通过 PnP 实现吗?
请尝试以下代码
# 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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.