2017-02-10 38 views
0

我是新來的這個Powershell/Office365/SharePoint的東西,所以這就是爲什麼我在這裏問一些幫助。我正在處理的問題是:我在Office365的SharePoint中的一個組中。有幾個人分享了一份文件,這些文件改變了這個文件。我想定期將此文檔下載到本地計算機。從Sharepoint下載Office 365中的特定文件與powershell

我認爲,最好的方法是使用PowerShell來完成這項任務。但是到現在爲止,我只能登錄到Office365使用PowerShell:

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="[email protected]" 
$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組,這是與我共享的文件一個小例子。

+0

我發現這個職位我的回答:http://stackoverflow.com/a/25476651/4872413 – kristian

回答

相關問題