[英]Powershell - Returning/Transferring an object from ForEach-Object
我目前能夠傳輸文件..但不知何故內容被忽略了。 我認為該對象未正確返回,但無法弄清楚。
$folder1 = "<external server>"
$folder2 = "<local path>"
# Get all files under $folder1, filter out directories
$firstFolder = Get-JFSChildItem $folder1 | Where-Object { -not $_.PsIsContainer }
$firstFolder | ForEach-Object {
# Check if the file, from $folder1, exists with the same path under $folder2
If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
{
$fileSuffix = $_.FullName.TrimStart($folder1)
Write-Host "$fileSuffix is only in folder1"
Receive-JFSItem $fileSuffix -destination $folder2
}
}
錯誤:Receive-JFSItem:沒有這樣的文件; 沒有這樣的文件。
錯誤:Receive-JFSItem <<<< $ fileSuffix -destination $ folder2
您錯誤地使用了TrimStart
。 TrimStart
接受一組要從參數中修剪的符號 ,並且您希望從其開始就將文件夾名稱修剪為精確的字符串。 而應該替換$folder1
與空字符串$_.fullname
。
If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
{
$fileSuffix = $_.FullName.Replace($folder1,"")
Write-Host "$fileSuffix is only in folder1"
Receive-JFSItem $fileSuffix -destination $folder2
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.