使用powershell从Sharepoint Office 365中的组下载特定文件

使用powershell从Sharepoint Office 365中的组下载特定文件,powershell,sharepoint,download,office365,document,Powershell,Sharepoint,Download,Office365,Document,我对Powershell/Office365/SharePoint之类的东西还不熟悉,所以这就是我在这里寻求帮助的原因。我正在处理的问题是:我在SharePoint上的一个组中。有一个文档在几个人之间共享,它改变了文档中的内容。我想定期将此文档下载到本地计算机 我认为,最好的方法是使用PowerShell完成此任务。但到目前为止,我只能使用PowerShell登录Office365: Set-ExecutionPolicy RemoteSigned Import-Module Msonline

我对Powershell/Office365/SharePoint之类的东西还不熟悉,所以这就是我在这里寻求帮助的原因。我正在处理的问题是:我在SharePoint上的一个组中。有一个文档在几个人之间共享,它改变了文档中的内容。我想定期将此文档下载到本地计算机

我认为,最好的方法是使用PowerShell完成此任务。但到目前为止,我只能使用PowerShell登录Office365:

Set-ExecutionPolicy RemoteSigned
Import-Module Msonline
$mycred = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $mycred -Authentication Basic -AllowRedirection
Import-PSSession $session
Connect-MsolService -Credential $mycred
问题是:现在该怎么办?当我在谷歌上搜索时,有很多不同的脚本,每个人都在使用其他功能,而这些功能似乎不是我想要的。我也没有找到任何关于这个话题的好教程

编辑

PhilC的回答有点帮助,但是缺少了一些东西,出现了一些问题

下面是我在进一步的部分之后添加的附加内容:

$sharepointURL="https://somesharepoint-my.sharepoint.com/"
$SPOUSer="myuser@email.com"
$SPOPassword="sometestingpassword"

// ...

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Taxonomy");

// ...

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($sharepointURL)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($SPOUser,$SPOPassword);

if (!$ctx.ServerObjectIsNull.Value) {
    Write-Host "Connected to SharePoint Online site: '$sharepointURL'" -ForegroundColor Green
}

Write-Host "Load Web ..."
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()

Write-Host "Load file ..."
$file = $ctx.Web.GetFileByServerRelativeUrl("/personal/myuser_email_com/Documents/test1.docx")
$ctx.Load($file)
$ctx.ExecuteQuery()
但这里出现了一些问题:

  • 我是否需要同时登录到Office365和SharePoint

  • 运行此脚本时,我收到以下错误消息:
    调用带有“0”参数的“ExecuteQuery”时出现异常:“访问被拒绝。Sie haben keine Berechtigung,diesen Vorgang auszuführen Order auf diese resource zuzugreifen”
    似乎我无权执行此操作或无法访问此资源。我做错什么了吗?这是我在Office365中创建的文件。我需要额外的权利吗?顺便说一句,我不是一个管理员,负责管理用户等等


  • 另一个注意事项:在第二个脚本中,我想创建一个从文档下载文件的小示例,然后再执行下一步并从SharePoint组下载一个与我共享的文件。

    此TechNet示例可能会有所帮助:

    此链接确实有所帮助。但还有一些问题。我将编辑我的初始问题。我在这篇文章中找到了我的答案: