简体   繁体   English

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

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

I am new to this Powershell / Office365 / SharePoint stuff, so this is why I am asking here for some help. 我是Powershell / Office365 / SharePoint的新手,所以这就是为什么我在这里寻求帮助。 The problem I am working on is this: I am in a group in SharePoint on Office365 . 我正在研究的问题是:我在Office365上的 SharePoint中属于一个小组。 There is a document shared between several people, which changing stuff in this document. 有几个人共享的文档,该文档中的内容有所更改。 I want to download this document to my local computer on a regular basis. 我想定期将此文档下载到我的本地计算机上。

I thought, the best way to do this is to use PowerShell for this task. 我认为,执行此操作的最佳方法是使用PowerShell执行此任务。 But up to now, I could only login into Office365 with 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

The problem is: What to do now? 问题是:现在该怎么办? When I am googling, there are a lot of different scripts, where everyone is using other functions which do not seem to be the one I am looking for. 当我进行谷歌搜索时,有很多不同的脚本,每个人都在使用其他功能,这些功能似乎并不是我想要的。 I also didn't found any good tutorial on this topic. 我也没有找到关于此主题的任何优秀教程。

Edit 编辑

The answer of PhilC helped a little, but there is something missing and there occurred some questions. PhilC的回答有所帮助,但是缺少了一些东西,并且出现了一些问题。

Here is the additional stuff, that I added after the part further up: 这是我在后续部分中添加的其他内容:

$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()

But some questions occurred here: 但是这里出现了一些问题:

  1. Do I need both logins, to Office365 and SharePoint? 我是否需要同时登录到Office365和SharePoint?

  2. When I am running this script, I get this error message: Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. Sie haben keine Berechtigung, diesen Vorgang auszuführen oder auf diese Ressource zuzugreifen" It seems, I do not have the rights to perform this operation or I cannot access to this resource. 当我运行此脚本时,收到以下错误消息: Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. Sie haben keine Berechtigung, diesen Vorgang auszuführen oder auf diese Ressource zuzugreifen"没有执行此操作的权限,或者我无法访问此资源。 Is there something wrong I am doing? 我在做错什么吗? It is a file I created in Office365. 这是我在Office365中创建的文件。 Do I need additional rights? 我需要其他权利吗? BTW, I am not an administrator, who manages the users and so stuff. 顺便说一句,我不是管理员,负责管理用户等等。

An additional note: With the second script, I wanted to create a small example for downloading a file from my documents, before doing the next step and downloading a file from a SharePoint group, which was shared with me. 附加说明:在第二个脚本中,我想创建一个小示例,从我的文档中下载文件,然后再执行下一步并从与我共享的SharePoint组中下载文件。

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

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