Quantcast
Channel: The PowerShell Guy : robocopy
Viewing all articles
Browse latest Browse all 6

PowerShell and Robocopy part 1

$
0
0

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\/\/


Viewing all articles
Browse latest Browse all 6

Trending Articles