none
Robocopy & Powershell parameter question

    Question

  • I am using a script that I found here that uses Powershell to call Robocopy with some parameters - source, destination & options.  The script is as follows:

    $s = "C:\Test\Source"
    $d = "C:\Test\Destination"
    $o = "/E"
    Robocopy $s $d $o
    IF ($LASTEXITCODE -eq 0)
    {
    Write-host copying complted successfully
    }
    Else
    {
    Write-host Error Copying File
    }

    I had wanted to have some other options to specify (logging, verbose output, etc) but if I put anything in the $o variable, it returns an error:  "Invalid Parameter #3" and then lists whatever is in $o.  

    I thought the command should be:

    robocopy c:\test\Source c:\test\Destination /E/V

    Am I doing something wrong?  

    Wednesday, March 13, 2013 4:48 PM

Answers

  • Treat $o as a collection.

    $s = "C:\Test\Source"
    $d = "C:\Test\Destination"
    $o = "/E","/V"
    Robocopy $s $d $o
    IF ($LASTEXITCODE -eq 0)
    {
    Write-host copying complted successfully
    }
    Else
    {
    Write-host Error Copying File
    }


    Boe Prox
    Blog | PoshWSUS | PoshPAIG | PoshChat

    • Marked as answer by Steve.O Wednesday, March 13, 2013 5:41 PM
    Wednesday, March 13, 2013 5:00 PM

All replies

  • Treat $o as a collection.

    $s = "C:\Test\Source"
    $d = "C:\Test\Destination"
    $o = "/E","/V"
    Robocopy $s $d $o
    IF ($LASTEXITCODE -eq 0)
    {
    Write-host copying complted successfully
    }
    Else
    {
    Write-host Error Copying File
    }


    Boe Prox
    Blog | PoshWSUS | PoshPAIG | PoshChat

    • Marked as answer by Steve.O Wednesday, March 13, 2013 5:41 PM
    Wednesday, March 13, 2013 5:00 PM
  • Thank you!  I knew it had to be something simple and/or stupid!!

    Wednesday, March 13, 2013 5:41 PM