RoboCopy ExitCodes the PowerShell way

‘Sup PSHomies!

Boe Prox recently blogged about building a enum that supports bitfields in PowerShell, definitely worth the read!

The first thing I thought about was RoboCopy! As you may or may not know, I’m a huge fan (no pun intended) of RoboCopy! I know that RoboCopy returns exitcodes, I just  didn’t do anything with it. Instead of relying on the exitcode, I’ve created a Get-LogSummary script to give me an overview of what failed or succeeded. Now that I see how easy it can be, why not give it a try? 😉

I’m running Windows 10 so I went with the PowerShell 5.0 version

RCExitCodes

So let’s give it a run!

#Start RoboCopy
$source  = '.\c#'     #Choose a source
$target  = '.\temp'   #Choose a target

robocopy $source $target /MIR

[RoboCopyExitCodes]$LASTEXITCODE

The target isn’t empty. I’m using /MIR to make a point. Be careful when choosing your target!

So the first run gave an exitcode of 3

RoboCopyFirstRun

Nice!

A second run gave an exitcode of 0

RoboCopySecondRun

No change indeed!

As a first impression, could be useful… So there you have it! RoboCopy exitcodes the *ahem* PowerShell way! 😛

Hope it’s worth something to you

Ttyl,

Urv

Advertisements

2 thoughts on “RoboCopy ExitCodes the PowerShell way

  1. Pingback: RoboCopy class | pshirwin

  2. Pingback: ACLs Folder class | pshirwin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s