Need to create a robocopy in Powershell 1.0

1

My ultimate goal is to mirror a folder and its subdirectories with the restriction of only copying files with the extensions, sln, vcxproj, cs, cpp, hpp, c, and h. There are far too many subfolders to manage this manually. I tried using the robocopy command in powershell, however it is not possible in Powershell 1.0. How can I achieve my objective in Powershell?

Improvised Solution

I managed to borrow some code and made some slight tweaks to it. It isn't robocopy per se, but it is managing to get close to what I am after. Note: this is just the code I copied, not the code I modified.

$Source = '\\ServerA\Folder\Root\'
$Destination = '\\ServerB\Folder\Root'

$SrcEntries = Get-ChildItem $Source -Recurse
foreach($Src in $SrcEntries)
{
 $SrcPath = $Src.fullname
 $DesPath = $SrcPath.Replace($Source, $Destination)

 #Check is source exist in dest
 if(test-Path $DesPath)
 {
  #if source was change 
  If(Compare-Object $SrcPath $DesPath) 
  {
   #then replace
   Copy-Item $SrcPath $DesPath -Force
  }
 }
 else
 {         
  #if dont exist then copy too
  Copy-Item $SrcPath $DesPath
 }
}

$DesEntries = Get-ChildItem $Destination -Recurse
foreach($Des in $DesEntries)
{
 $DesPath = $Des.fullname
 $SrcPath = $DesPath.Replace($Destination, $Source)

 if((test-Path $SrcPath) -eq $false)
 {
  #if source dont exist then delete dest
  Remove-Item $DesPath
 }
}

torrho

Posted 2014-04-07T15:55:39.247

Reputation: 135

"I tried using the robocopy command in powershell, however it is not possible in Powershell 1.0." It should work fine - What exact command did you try in PS? What were the results? – Ƭᴇcʜιᴇ007 – 2014-04-07T17:24:58.807

@techie007 This Link shows a list of PS 1.0 commands. I tried robocopy on my machine (powershell 1.0 - windows XP), it did not recognize the command.

– torrho – 2014-04-07T17:44:23.110

Answers

3

Robocopy is not a PowerShell command. It's a Windows command-line utility, and it's not included with XP.

You need to get the Windows Server 2003 Resource Kit Tools to get Robocopy for XP. Once you have it, you'll be able to utilize it in PowerShell.

Ƭᴇcʜιᴇ007

Posted 2014-04-07T15:55:39.247

Reputation: 103 763