# RoboCopy Powershell Module

By
,
Powershell
,
Modules
Published 2022-08-09

Link To Download
https://www.powershellgallery.com/packages/RoboCopy/1.0.0

RoboCopy minus the y
RoboCopy minus the y

# Another Crescendo Module 🚇

Today I was looking at some freelance work, just seeing what is out there, as I would quite fancy just being a full time Powershell scripting person. It just seems that the jobs for pure Powershell just do not exist. It seems most Powershell jobs in the United Kingdom consist of being a senior cloud engineer, where it seems only a tiny bit of the job role mentions Powershell. Anyways whilst looking at Powershell project work available out there in the wild. This all stemmed from me trying to be helpful, and answer a question on a LinkedIn Powershell group. Next thing I know I am getting lots of messages from this random person, basically asking me to re-write the existing script they have as it is not working. I spent a good 20 or more minutes helping this person to even run the script. So I kind of politely mentioned that I sadly cannot devote my entire evening as time is money. Next thing I know is they actually said they would pay me for my time, and they had posted the job on people per hour site. So next thing I knew I was on there:-

Me on People Per Hour
https://pph.me/adambacon

Going back to the project I saw which was on another site, someone wanted to copy file paths longer than the 260 limit, but in Powershell. I was thinking I am sure this cannot be done, as I did put a bid in for the project. So to get one step further in being able to pull this off, I needed a way to be able to copy file directories longer than the 260 limit in Powershell. After a bit of reading I find that this is possible to do with the trusted robocopy.exe but this is not pure powershell. So I made it into a Powershell cmdlet with parameters that actually made sense.

This was such a classic when it came out
This was such a classic when it came out

# RoboCopy 🖨️

On the Powershell Gallery
https://www.powershellgallery.com/packages/RoboCopy/1.0.0

The thing I find with these classic DOS commands, is the parameters used as in the way you type the parameter normally makes no sense in correlation to what that parameter does. I normally find myself reading the help on the parameters for DOS programs more than once to make sure I fully understand it. So the great thing with RoboCopy is a lot of the actual parameters are just switch parameters either on or off. I mean I didn't include every-single possible parameter as I wanted to get this built and published within a small time-frame. So going back to what I was saying about complicated named parameters for what they actually do, I thought I can now eradicate that, with some slightly longer named parameters, but named with what they actually do.

RoboCopy is just as tough as RoboCop
RoboCopy is just as tough as RoboCop

# Example ▶️

As mentioned pretty much all the parameters are switches apart from the -NumberOfRetries and the -WaitTime which expect an integer for the parameter value.

Example 1

Start-RoboCopy -SourcePath "C:\Builds\MyBlog\" -DestinationPath "C:\Builds\new\" -CopySubdirectoriesNotEmpty -EnableMultiThreadedCopy -ShowSizesInBytes

Example 2

Start-RoboCopy -SourcePath "C:\Buids\MyBlog\" -DestinationPath "C:\Buids\new\" -ListOnly

# Update 🔈

So I guess the Powershell people are more movie die-hards than comic-book aka graphic novels type of people. Why do you say that? Well not that I am the best at tweeting, but I am lucky to get a like. You mention Robocop in a tweet, suddenly you are the new cool-kid in town 😎 and for the first time since being on twitter I got triple digit likes

Amazed by the amount of likes for this project...thank you
Amazed by the amount of likes for this project...thank you
I mean this week I am looking for work and was feeling a bit down that I am thinking it's day 3 I should have found something by now, then 💥 boom this happens and made me feel much happier 😄 that even if it was for the icon to accompany the module it got some love aka likes, which was way more than planned 🥰 so just how to make someone feel better when they looking for a job give them over a 100 likes ❤️ I can vouch it really does work. Anyways I was on twitter and just chilling with my homies and was recommended to get on discord for Powershell. Now I know my Mrs uses that for her gaming, but personally I think I tried it like once but then forgot about it, but anyways I got back on discord and saw about someone saying that wanted to implement a robocopy type script. I was like, dude I just made the robocopy.exe into a cmdlet, you could use that. I then posted him the link to the official robocopy Microsoft page here (which in hindsight I should have posted earlier on in the post)
Official Microsoft Docs for Robocopy.exe
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
He was like I need the /MOVE parameter and I was like 🙄 oh yeah I didn't include that one 😶 give me 5 minutes...

Uppdated RoboCopy module
https://www.powershellgallery.com/packages/RoboCopy/1.0.1

Which now shows

PS C:\Users\Adz> import-module robocopy
PS C:\Users\Adz> gcm -module robocopy

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Start-RoboCopy                                     1.0.1      robocopy

PS C:\Users\Adz> help Start-RoboCopy

NAME
    Start-RoboCopy

SYNTAX
    Start-RoboCopy [[-SourcePath] <string>] [[-DestinationPath] <string>] [[-NumberOfRetries] <int>] [[-WaitTime]
    <int>] [-ListOnly] [-CopySubdirectoriesNotEmpty] [-NoJobHeader] [-ShowSizesInBytes] [-IncludeFullPathName]
    [-NoClass] [-NoDirectoryList] [-ShowTimeStamp] [-ExcludeJunctionPoints] [-RestartTransferIfInterrupted]
    [-EnableMultiThreadedCopy] [-MoveThenDeleteFromSource] [<CommonParameters>]

I added a new parameter -MoveThenDeleteFromSource which does exactly what it says on the tin. It will use robocopy to copy the contents to the new directory then delete the contents from the original destination once the copy is completed.

I know I may have broken some best methods or practices, but I just wanted the parameter names to make as much sense as possible, as I know that personally that is what puts me off using oldie but goodie DOS commands.

Listing of the parameters I did include on this initial release for the RoboCopy module.

-CopySubdirectoriesNotEmpty

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-DestinationPath <string>

    Required?                    false
    Position?                    1
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-EnableMultiThreadedCopy

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-ExcludeJunctionPoints

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-IncludeFullPathName

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-ListOnly

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-NoClass

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-NoDirectoryList

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-NoJobHeader

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-NumberOfRetries <int>

    Required?                    false
    Position?                    2
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-RestartTransferIfInterrupted

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-ShowSizesInBytes

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-ShowTimeStamp

    Required?                    false
    Position?                    Named
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-SourcePath <string>

    Required?                    false
    Position?                    0
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false


-WaitTime <int>

    Required?                    false
    Position?                    3
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    Accept wildcard characters?  false

Thanks for reading I hope this module finds a place in your toolkit. 😁