我使用了以下網站來幫助我解決這個問題並排除故障。如何使用PowerShell從SharePoint下載文件?
- Download file from SharePoint
- How to download newest file from SharePoint using PowerShell
- Mike Smith's Tech Training Notes SharePoint, PowerShell and .Net!
- Upload file to a SharePoint doc library via PowerShell
- Download latest file from SharePoint Document Library
- How to iterate each folders in each of the SharePoint websites using PowerShell
- PowerShell's Get-ChildItem on SharePoint Library
我試圖從SharePoint文件夾中下載隨機文件,並且當它確實知道文件名和擴展名時,我就可以使用它。
用名和擴展名工作代碼:
$SharePoint = "https://Share.MyCompany.com/MyCustomer/WorkLoad.docx"
$Path = "$ScriptPath\$($CustomerName)_WorkLoad.docx"
#Get User Information
$user = Read-Host "Enter your username"
$username = "[email protected]"
$password = Read-Host "Enter your password" -AsSecureString
#Download Files
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($UserName, $Password)
$WebClient.DownloadFile($SharePoint, $Path)
不過,我似乎不能夠想出如何與未知名或擴展名的多個文件做到這一點。
我試過映射驅動器,只能以「驅動器映射失敗」結束&「找不到網絡路徑。」錯誤:
$SharePoint = Read-Host 'Enter the full path to Delivery Site'
$LocalDrive = 'P:'
$Credentials = Get-Credential
if (!(Test-Path $LocalDrive -PathType Container)) {
$retrycount = 0; $completed = $false
while (-not $completed) {
Try {
if (!(Test-Path $LocalDrive -PathType Container)) {
(New-Object -ComObject WScript.Network).MapNetworkDrive($LocalDrive,$SharePoint,$false,$($Credentials.username),$($Credentials.GetNetworkCredential().password))
}
$Completed = $true
}
Catch {
if ($retrycount -ge '5') {
Write-Verbose "Mapping SharePoint drive failed the maximum number of times"
throw "SharePoint drive mapping failed for '$($SharePoint)': $($Global:Error[0].Exception.Message)"
} else {
Write-Verbose "Mapping SharePoint drive failed, retrying in 5 seconds."
Start-Sleep '5'
$retrycount++
}
}
}
}
我也使用了下面的代碼,類似的結果或根本沒有結果。
#Get User Information
$user = Read-Host "Enter your username"
$username = "[email protected]"
$password = Read-Host "Enter your password" -AsSecureString
#Gathering the location of the Card Formats and Destination folder
$Customer = "$SharePoint\MyCustomer"
$Products = "$Path\$($CustomerName)\Products\"
#Get Documents from SharePoint
$credential = New-Object System.Management.Automation.PSCredential($UserName, $Password)
New-PSDrive -Credential $credential -Name "A" -PSProvider "FileSystem" -Root "$SharePoint"
net use $spPath #$password /USER:[email protected]
#Get PMDeliverables file objects recursively
Get-ChildItem -Path "$Customer" | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $Products -Force -Verbose
錯誤:Get-SPWeb:術語'Get-SPWeb'不被識別爲cmdlet,函數, 腳本文件或可操作程序的名稱。檢查名稱的拼寫,或者如果包含路徑 ,請驗證路徑是否正確,然後重試。 – Underdog
您是使用本機PowerShell還是SharePoint Management Shell?如果是前者,則在使用任何SharePoint cmdlet – Stevangelista
本機PowerShell ISE之前,需要先運行「Add-PSSnapin Microsoft.SharePoint.PowerShell」。我運行了「Add-PSSnapin Microsoft.SharePoint.PowerShell」,我仍然收到了完全相同的錯誤。 – Underdog