Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

PowerShell and Robocopy part 1

listening to the PowerScripting Podcast - Episode 41 RoboCopy was mentioned, and I remembered some Robocopy stuff I still had laying around :

And I will use it as a series about using / wrapping a native tool from PowerShell, I start out with a bit of Text Processing, 

#############################################################################################
## Make RoboCopy Help Object
#############################################################################################

$RoboHelp = robocopy /? | Select-String '::'
$r = [regex]'(.*)::(.*)'
$RoboHelpObject = $RoboHelp | select `
    @{Name='Parameter';Expression={ $r.Match( $_).groups[1].value.trim()}},
    @{Name='Description';Expression={ $r.Match( $_).groups[2].value.trim()}}

$RoboHelpObject = $RoboHelpObject |% {$Cat = 'General'} {
    if ($_.parameter -eq '') { if ($_.Description -ne ''){
        $cat = $_.description -replace 'options :',''}
    } else {
        $_ | select @{Name='Category';Expression={$cat}},parameter,description
    }
}

This peice of PowerShell code basically just starts Robocopy /?  , parses the resulting help text into an Custom object,  this gives us a Robocopy help object in the variable $RoboCopyHelpObject and we can check it like this :

image

You can see that as I have the robocopy help in object form now I can do for example grouping and counting of the Help topics,

I did a series about TextScraping where you can find more examples of text to object translations, so I won't go into much detail here but we will use this object we created later in this series.

Enjoy,

Greetings /\/\o\/\/

Published Tuesday, September 16, 2008 4:15 PM by MoW

Comments

# Weekly news from The PowerShell world

Hi, and welcome to the first of many weekly news post from the PowerShell world. By The Scandinavian

Wednesday, September 24, 2008 7:53 AM by The Wall

# PowerShell and Robocopy part 5

  I this part I will cover the code for the "PowerShell Robocopy GUI" as shown in PowerShell

Wednesday, October 01, 2008 4:37 PM by The PowerShell Guy
Anonymous comments are disabled