繁体   English   中英

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

[英]Download a specific file from a group in Sharepoint at Office 365 with powershell

我是Powershell / Office365 / SharePoint的新手,所以这就是为什么我在这里寻求帮助。 我正在研究的问题是:我在Office365上的 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()

但是这里出现了一些问题:

  1. 我是否需要同时登录到Office365和SharePoint?

  2. 当我运行此脚本时,收到以下错误消息: Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. Sie haben keine Berechtigung, diesen Vorgang auszuführen oder auf diese Ressource zuzugreifen"没有执行此操作的权限,或者我无法访问此资源。 我在做错什么吗? 这是我在Office365中创建的文件。 我需要其他权利吗? 顺便说一句,我不是管理员,负责管理用户等等。

附加说明:在第二个脚本中,我想创建一个小示例,从我的文档中下载文件,然后再执行下一步并从与我共享的SharePoint组中下载文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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