יום חמישי, 8 בינואר 2026

Copy a folder by Robocopy command in restartable mode - powershell

 

#

Function Copy-RestartableFolder {

    Param (

        [Parameter (Mandatory)]

        [String] $Source,

        [String] $Destination,

        [Switch] $ListOnly,

        [Parameter ()]

        [String] $Name

    )

    # Variables

$Name     = Split-Path -Path $Source -Leaf

$RoboCopy = "Robocopy.exe"

$LogFile  = "$Env:Temp\MyProject1.log"

$Switches = @( '/Z', '/E', '/R:0', '/W:0', '/MT', '/XA:SH', '/L' )

# ===============================

    # ListOnly / List Only

# ===============================

If ( $ListOnly ) {

        $RoboCopyArgs = @( $Source, "$Destination\$Name" ) + $Switches

        Write-Host "Listing Mode Only :: ( No Copying )" -ForegroundColor Yellow -BackgroundColor Black

        & $RoboCopy @RoboCopyArgs

        Return

    }

# ===============================

    # Copy Now

# ===============================

$Execute = $Switches + @( "/Log+:$LogFile" ) | ? { $_ -ne '/L' }

$RoboCopyExecution = @( $Source, "$Destination\$Name" ) + $Execute

Write-Host "Actual Copy :: Copying Your Items ..." -ForegroundColor Yellow -BackgroundColor Black

& $RoboCopy @RoboCopyExecution

GCI -Path "$Destination\$Name"

Get-Content $LogFile

}

#



בצע סימולציה

# Sources

$Source = "$Env:UserProfile\Documents\New folder1"

$Destination = "$Env:UserProfile\Documents\New folder2"

#

Copy-RestartableFolder -Source $Source -Destination $Destination -ListOnly


בצע העתקה

Copy-RestartableFolder -Source $Source -Destination $Destination



אין תגובות:

הוסף רשומת תגובה

Copy a folder by Robocopy command in restartable mode - powershell

  # Function Copy-RestartableFolder {     Param (         [Parameter (Mandatory)]         [String] $Source,         [String] $Destination,  ...