i have the below script i need to run on a server running PS 2.0... i have tested it on my local machine PS 3.0 and it works fine.... however, when i run it on the server (2008 R2) i get an error on ($folder in (Get-ChildItem -Directory $sourceFolder)
) saying that -Directory
is unexpected... but only on the server.
Is there an issue with my script, or something else?
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
}