我有以下脚本我需要在运行PS 2.0的服务器上运行...我已经在我的本地机器PS 3.0上测试了它工作正常....但是,当我在服务器上运行它时(2008年) R2)我收到错误($folder in (Get-ChildItem -Directory $sourceFolder)
)说-Directory
是意外的......但只在服务器上。
我的脚本或其他内容是否存在问题?
Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "Unrestricted"
$sourceFolder = "server1\a\b\c"
$destFolder = "server2\a\b\c"
New-Item -Path "$destFolder\Log" -ItemType Directory | Out-Null
foreach ($folder in (Get-ChildItem -Directory $sourceFolder)) {
"robocopy `"$($sourceFolder)\$($folder)\zArchive\Data files to Nov 13`" `"$($destFolder)\$($folder)\Data files to Nov 13`" /E /MOVE /DCOPY:T /log+:`"$($destFolder)\Log\log.log`"" | Out-File zArchiveMove.txt -Append
"robocopy `"$($sourceFolder)\$($folder)\Data files to Nov 13`" `"$($destFolder)\$($folder)\Data files to Nov 13`" /E /MOVE /DCOPY:T /log+:`"$($destFolder)\Log\log.log`"" | Out-File zArchiveMove2.txt -Append
}
答案 0 :(得分:0)
V2.0中没有目录参数。在那些日子里(LOL),我们使用了$ PSIsContainer
foreach ($folder in (Get-ChildItem $sourceFolder | ? {$_.PSIsContainer}))
答案 1 :(得分:0)
还有PowerShell问题,而且时间不多了。我最终使用批处理文件来完成比ps脚本短一点的工作。如果有人发现它有用,我会认为它是共享的。 :)
for /f "delims=|" %%s in ('dir /ad/b') do robocopy "\\server\source\%%s\folder1" "\\server2\dest\%%s\folder1" /E /MOVE