我知道這已經被問了一百萬次,但我似乎找不到任何適合我的東西。我不知道是否存在權限問題或什么,但我正在嘗試使用任務計劃程式中的 PowerShell 腳本將檔案從一臺服務器移動到另一臺服務器,并且它在停止作業之前作業了大約一周。任務計劃程式沒有錯誤,而且我根本不精通 PowerShell,我只是想讓我們的 CMS 經理快速簡單地將她的檔案從網站移動到另一臺服務器上的檔案夾。
$ORG = "E:\folders\uploads\" ## enter current source folder
$DEST= "\\server-folder-structure\uploads\" ## enter your destination folder
foreach ($ORG in gci $DEST -include *.doc,*.docx,*.pdf,*.png,*.gif,*.jpg,*.jpeg,*.html,*.htm -recurse)
{
Move-Item -path $ORG -destination $DEST ## Move the files to the destination folder
}
我也試過這個,希望它能作業,但仍然沒有檔案被移動。
Get-ChildItem E:\folder-structure\uploads\* -Include *.doc,*.docx,*.pdf,*.png,*.gif,*.jpg,*.jpeg,*.html,*.htm -Recurse |ForEach-Object { Move-Item $_.FullName \\server-folder-structure\uploads\ }
難道我做錯了什么?是否有我需要設定但我不知道的檔案夾的權限?PowerShell 不是最好的方法嗎?提前致謝。
uj5u.com熱心網友回復:
我相信你做這件事比它應該做的更難(關于 PowerShell 對你來說是新手)。如果您想直接通過管道傳輸到以下位置,則不需要對任何示例進行回圈Move-Item:
$ORG = "E:\folders\uploads\" ## enter current source folder
$DEST = "\\server-folder-structure\uploads\" ## enter your destination folder
$filterFor = "*.doc","*.docx","*.pdf","*.png","*.gif","*.jpg","*.jpeg","*.html","*.htm"
Get-ChildItem $ORG -Include $filterFor -File -Recurse |
Move-Item -Destination $DEST -WhatIf
至于您嘗試了什么,正如Mathias指出的那樣,您將搜索$DEST檔案不存在的位置,因為它們只會在$ORG; 鑒于那是實際的源檔案夾。
- 這也會
$ORG用迭代中的當前專案覆寫你的變數:foreach ($ORG in gci ..){ ... }。 - 意思是,你的
Move-Item將是無效的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444126.html
標籤:电源外壳
