none
Use Robocopy Powershell Script RRS feed

  • Question

  • Hello,

    this is a great script with nice output pictures form a robocopy command.

    http://thepowershellguy.com/blogs/posh/archive/2008/09/21/powershell-and-robocopy-part-3.aspx

    How can i use this script at robocopy command in powershell script?

    When i start this script i get the error:

    Missing expression after unary operator '-'.
    At C:\Temp\RoboCopyWrapper.ps1:161 char:4
    +   - <<<< Value {"Details : " + $this.count} -force
        + CategoryInfo          : ParserError: (-:String) [], ParseException
        + FullyQualifiedErrorId : MissingExpressionAfterOperator

    I hope somebody can help me,

    Horst


    Thanks Horst MOSS 2007 Farm, MOSS 2010 Farm, TFS 2010

    Friday, February 24, 2012 6:59 AM

Answers

  • I download RoboCopyWrapper.ps1 from http://poshcode.org/?show=603.

    Missing expression after unary operator '-'.
    At C:\Temp\RoboCopyWrapper.ps1:161 char:4
    +   - <<<< Value {"Details : " + $this.count} -force
        + CategoryInfo          : ParserError: (-:String) [], ParseException
        + FullyQualifiedErrorId : MissingExpressionAfterOperator

    Error occurs,because 160 line commented out ,but 161 line not commented out.

    #Add-Member -InputObject $RoboDetails -Name 'toString' -MemberType ScriptMethod `
      -Value {"Details : " + $this.count} -force

    That would fix the error:

    1) Comment lines 160,161,175,176,186,187

    or

    2) Uncomment this lines

    • Marked as answer by wuwu Friday, February 24, 2012 12:02 PM
    Friday, February 24, 2012 10:18 AM
  • 248-251 replace to:

    $RoboStatus.Errors | 
      select *,@{name='Warnings';e={$e = $_;($robostatus.warnings |? {$_.info -eq $e.info})}} |% {
        $_ | fl error,Info 
    	$_.warnings | sort -u info,message | ft [tecm]* -a  
    }

    48 replace to:

    -Value ([datetime]::ParseExact($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',[Globalization.CultureInfo]::InvariantCulture)) `


    77 replace to:

     -Value ([datetime]::ParseExact($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',[Globalization.CultureInfo]::InvariantCulture))`
    207 replace to:
    $RoboStatus.Options.split()[1..100] | % { $par = $_ ;$RoboHelpObject |? {$_.parameter -eq $par} } | Out-Default | ft -a



    • Edited by Kazun Friday, February 24, 2012 11:48 AM
    • Marked as answer by wuwu Friday, February 24, 2012 12:02 PM
    Friday, February 24, 2012 11:39 AM

All replies

  • (gc C:\Temp\RoboCopyWrapper.ps1) -replace '`\s+','`' > C:\Temp\RoboCopy.ps1

    And comment this string:

    160-161

    #Add-Member -InputObject $RoboDetails -Name 'toString' -MemberType ScriptMethod`

    #-Value {"Details : " + $this.count} -force

    175-176

    #Add-Member -InputObject $RoboWarnigs -Name 'toString' `

    #  -MemberType ScriptMethod -Value {"Details : " + $this.count} -force

    186-187

    #Add-Member -InputObject $RoboErrors -Name 'toString' `

    #  -MemberType ScriptMethod -Value {"Details : " + $this.count} -force

    • Edited by Kazun Friday, February 24, 2012 8:06 AM
    Friday, February 24, 2012 7:59 AM
  • Thank you for hte answer!

    Do understand it really:

    First i have to replace at RoboCopyWrapper.ps1 everything with  '`\s+' to '`' this?

    Secound, i have to uncomment this: 

    #Add-Member -InputObject $RoboDetails -Name 'toString' -MemberType ScriptMethod`

    #-Value {"Details : " + $this.count} -force

    175-176

    #Add-Member -InputObject $RoboWarnigs -Name 'toString' `

    #  -MemberType ScriptMethod -Value {"Details : " + $this.count} -force

    186-187

    #Add-Member -InputObject $RoboErrors -Name 'toString' `

    #  -MemberType ScriptMethod -Value {"Details : " + $this.count} -force#

    and then start the script again?horst


    Thanks Horst MOSS 2007 Farm, MOSS 2010 Farm, TFS 2010

    Friday, February 24, 2012 9:40 AM
  • I download RoboCopyWrapper.ps1 from http://poshcode.org/?show=603.

    Missing expression after unary operator '-'.
    At C:\Temp\RoboCopyWrapper.ps1:161 char:4
    +   - <<<< Value {"Details : " + $this.count} -force
        + CategoryInfo          : ParserError: (-:String) [], ParseException
        + FullyQualifiedErrorId : MissingExpressionAfterOperator

    Error occurs,because 160 line commented out ,but 161 line not commented out.

    #Add-Member -InputObject $RoboDetails -Name 'toString' -MemberType ScriptMethod `
      -Value {"Details : " + $this.count} -force

    That would fix the error:

    1) Comment lines 160,161,175,176,186,187

    or

    2) Uncomment this lines

    • Marked as answer by wuwu Friday, February 24, 2012 12:02 PM
    Friday, February 24, 2012 10:18 AM
  • hello,

    thank you, now it runs with errors:

    ------------------------------------------------------------------------------

                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         2         0         2         0         0         0
       Files :        19         0        19         0         0         0
       Bytes :    53.1 k         0    53.1 k         0         0         0
       Times :   0:00:00   0:00:00                       0:00:00   0:00:00

       Ended : Fri Feb 24 12:11:38 2012
    Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
    At C:\temp\RoboCopyWrapper.ps1:48 char:38
    +        -Value ([datetime]::ParseExact <<<< ($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',$null)) `
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
    At C:\temp\RoboCopyWrapper.ps1:77 char:41
    +           -Value ([datetime]::ParseExact <<<< ($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',$null))`
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

     

    Source      : c:\temp\
    Destination : c:\temp2\
    FileName    : *.*
    Options     : *.* /V /S /COPY:DAT /NP /R:2 /W:5
    Directories : Total:2 Copied:0 Skipped:2 Mismatch:0 FAILED:0 Extras:0
    files       : Total:19 Copied:0 Skipped:19 Mismatch:0 FAILED:0 Extras:0
    bytes       : Total:54374.4 Copied:0 Skipped:54374.4 Mismatch:0 FAILED:0 Extras:0
    Details     : {@{Action=Directory; Size=14; Directory=c:\; Name=c:\temp\}, @{Action=same; Size=3059; Directory=c:\temp\
                  ; Name=.robocopy.log}, @{Action=same; Size=5798; Directory=c:\temp\; Name=Copy_IIS_Config.ps1}, @{Action=
                  same; Size=377; Directory=c:\temp\; Name=Deploy.bat}...}
    Warnings    :
    Errors      :

    Time elapsed : 0
    out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not
     in the correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with th
    e default formatting.
        + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperationException
        + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

    First error : ParseExact" with "3" argument(...

    Secound Problem: out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not

    I hope you can help me again, thank you very much!

    Horst


    Thanks Horst MOSS 2007 Farm, MOSS 2010 Farm, TFS 2010

    Friday, February 24, 2012 11:14 AM
  • 248-251 replace to:

    $RoboStatus.Errors | 
      select *,@{name='Warnings';e={$e = $_;($robostatus.warnings |? {$_.info -eq $e.info})}} |% {
        $_ | fl error,Info 
    	$_.warnings | sort -u info,message | ft [tecm]* -a  
    }

    48 replace to:

    -Value ([datetime]::ParseExact($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',[Globalization.CultureInfo]::InvariantCulture)) `


    77 replace to:

     -Value ([datetime]::ParseExact($matches[1].trim(),'ddd MMM dd HH:mm:ss yyyy',[Globalization.CultureInfo]::InvariantCulture))`
    207 replace to:
    $RoboStatus.Options.split()[1..100] | % { $par = $_ ;$RoboHelpObject |? {$_.parameter -eq $par} } | Out-Default | ft -a



    • Edited by Kazun Friday, February 24, 2012 11:48 AM
    • Marked as answer by wuwu Friday, February 24, 2012 12:02 PM
    Friday, February 24, 2012 11:39 AM
  • hello kazun,

    great, thank you very, very much, it works!!!

    horst


    Thanks Horst MOSS 2007 Farm, MOSS 2010 Farm, TFS 2010

    Friday, February 24, 2012 12:02 PM