PowerShell
Edit|Remove
import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1'CD “$(get-psdrive –PSProvider CMSite):\” 
 
Write-Host "Gathering content from $($SourceDP)" 
$DeploymentPackages = Get-CMDeploymentPackage -DistributionPointName $SourceDP 
 
ForEach ($DeploymentPackage in $DeploymentPackages) { 
 
    If ($Prestage) { $command = "Publish-CMPrestageContent "#If we are in prestage mode, we'll create prestage content 
    Else { $command = "Start-CMContentDistribution "#If we are in finalize mode, we'll assign content distribution to the DP 
 
    Switch ($DeploymentPackage.ObjectTypeID) { #Set command arguments depending on the content's type ID 
 
        2  { $command +"-PackageID $($DeploymentPackage.PackageID) " } #Package 
        14 { $command +"-OperatingSystemInstallerId $($DeploymentPackage.PackageID) "#Operating System Installer Package 
        18 { $command +"-OperatingSystemImageId $($DeploymentPackage.PackageID) "#Operating System Image Package 
        19 { $command +"-BootImageId $($DeploymentPackage.PackageID) "#OSD Boot Image Package 
        23 { $command +"-DriverPackageID $($DeploymentPackage.PackageID) "#Driver Package 
        24 { $command +"-DeploymentPackageID $($DeploymentPackage.PackageID) "#Software Update Package 
        31 { $command +"-ApplicationName '$($DeploymentPackage.Name)' "#Application Package 
    } 
 
    If (($DeploymentPackage.ObjectTypeID -eq 20) -or ($DeploymentPackage.ObjectTypeID -eq 21)) { 
        Write-Host "Skipping $($DeploymentPackage.PackageID) due to unsupported content type"  #Device Settings and Task Sequence packages cannot be prestaged 
    } 
    Else 
    { 
        If ($Finalize) { #If we're in finalize mode, add the final command argument and invoke the command 
            $command +"-DistributionPointName $($TargetDP)" 
            Write-Host "Assigning $($DeploymentPackage.PackageID) to $($TargetDP)" 
            Invoke-Expression $command    
        } 
        Else 
        { # If we're in prestage mode, add the final command arguments, invoke the command, and move the pkgx file to the content share 
            $command +"-FileName '$($env:TEMP)\$($DeploymentPackage.PackageID).pkgx' -DistributionPointName $($SourceDP)" 
            Write-Host "Creating prestage content file $($env:TEMP)\$($DeploymentPackage.PackageID).pkgx" 
            Invoke-Expression $command 
            cd "$($env:TEMP)" #Fix so that we can use the move-item cmdlet without getting a provider error 
            Write-Host "Moving $($env:TEMP)\$($DeploymentPackage.PackageID).pkgx to $($ContentShare)\$($DeploymentPackage.PackageID).pkgx" 
            Move-Item "$($env:TEMP)\$($DeploymentPackage.PackageID).pkgx" "$($ContentShare)\$($DeploymentPackage.PackageID).pkgx" -Force 
            CD “$(get-psdrive –PSProvider CMSite):\” #Switch back the the SCCM PSProvider before we continue 
        } 
    } 
}
 

# Ken Smith
# Microsoft Premier Field Engineer (PFE)
# http://twitter.com/pfeken
# http://blogs.technet.com/b/kensmith/
#
# 07/28/2013
# Rev 1.1
#
# This script demonstrates how to clone the contents of one distribution point onto another.  This is useful if you need to
# reload a DP, or if you are migrating to new hardware and do not want to copy packages over the WAN.
#
# Usage: CloneDP <mode> <mode options>
#
# Modes
# =====
#     -PreStage - This mode will create prestage files for all of the content on the source DP
#     -Finalize - This mode will distribute content to the destination DP - any prestaged content will use the local copy
#       
# Mode Options
# ============
#     -TargetDP (Required) - The destination DP for the clone operation
#     -SourceDP (Required) - The source DP for the clone operation
#     -ContentShare (Optional) - This option is required for the prestage mode, prestage files will be moved here for import
#
# This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. 
# THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
# We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object
# code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software
# product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the
# Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims
# or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.