‘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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Flags()] Enum RoboCopyExitCodes{ | |
NoChange = 0 | |
OKCopy = 1 | |
ExtraFiles = 2 | |
MismatchedFilesFolders = 4 | |
FailedCopyAttempts = 8 | |
FatalError = 16 | |
} | |
(0..16).ForEach{ | |
[PSCustomObject]@{ | |
Number = $_ | |
ExitCodes = [RoboCopyExitCodes]$_ | |
} | |
} |
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
Nice!
A second run gave an exitcode of 0
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
Pingback: RoboCopy class | pshirwin
Pingback: ACLs Folder class | pshirwin