gpt4 book ai didi

powershell - 下载SharePoint文件-PowerShell异常:不能从重写的覆盖范围之外调用WriteObject和WriteError方法。

转载 作者:行者123 更新时间:2023-12-03 00:09:41 30 4
gpt4 key购买 nike

我收到以下错误

Get-PnPFile : The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.



运行此PowerShell脚本时:
$cred = Get-Credential;
$webUrl = "https://...sharepoint.com";
$listUrl = "..";
$destination = "C:\\Folder1"

Connect-PnPOnline -Url $webUrl -Credentials $cred
$web = Get-PnPWeb
$list = Get-PNPList -Identity $listUrl

function ProcessFolder($folderUrl, $destinationFolder) {
$folder = Get-PnPFolder -RelativeUrl $folderUrl
$tempfiles = Get-PnPProperty -ClientObject $folder -Property Files

if (!(Test-Path -Path $destinationfolder)) {
$dest = New-Item $destinationfolder -Type Directory
}

$total = $folder.Files.Count
for ($i = 0; $i -lt $total; $i++) {
$file = $folder.Files[$i]

Get-PnPFile -ServerRelativeUrl $file.ServerRelativeUrl -Path
$destinationfolder -FileName $file.Name -AsFile
}
}

function ProcessSubFolders($folders, $currentPath) {
foreach ($folder in $folders) {
$tempurls = Get-PnPProperty -ClientObject $folder -Property ServerRelativeUrl
# Avoid Forms folders
if ($folder.Name -ne "Forms") {
$targetFolder = $currentPath +"\"+ $folder.Name;
ProcessFolder
$folder.ServerRelativeUrl.Substring($web.ServerRelativeUrl.Length)
$targetFolder
$tempfolders = Get-PnPProperty -ClientObject $folder -Property Folders
ProcessSubFolders $tempfolders $targetFolder
}
}
}

# Download root files
ProcessFolder $listUrl $destination + "\"
# Download files in folders
$tempfolders = Get-PnPProperty -ClientObject $list.RootFolder -Property Folders
ProcessSubFolders $tempfolders $destination + "\"

该脚本可以在Win10 PC上正常运行,但不能在Win Server上运行。有人可以告诉我原因是什么吗?

最佳答案

在今天早上再试一次之后,以上脚本可在Windows 10 PC和Windows Server上使用,

亚历山德拉

关于powershell - 下载SharePoint文件-PowerShell异常:不能从重写的覆盖范围之外调用WriteObject和WriteError方法。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52150286/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com