1

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
} 
alroc
  • 27,574
  • 6
  • 51
  • 97
user3795654
  • 86
  • 3
  • 12

2 Answers2

0

There wasn't a directory parameter in V2.0. Back in those days (LOL) we used $PSIsContainer

foreach ($folder in (Get-ChildItem $sourceFolder | ? {$_.PSIsContainer})) 
Cole9350
  • 5,444
  • 2
  • 34
  • 50
0

Still having issues with powershell, and running out of time. I ended up using a batch file to complete the work which is a little shorter than the ps script. thought id share it if anyone finds it useful. :)

for /f "delims=|" %%s in ('dir /ad/b') do robocopy "\\server\source\%%s\folder1" "\\server2\dest\%%s\folder1" /E /MOVE 
user3795654
  • 86
  • 3
  • 12