A PowerShell script which provides the following:
- Mount remote/target server share with given username/password credentials.
- Copy all
$SourcePath
files to target share ($TargetServer
/$TargetShare
) recursively. - Finally, clean up all orphaned directories/files from target share.
Usage example
Param (
[string]$SourcePath = ".",
[Parameter(Mandatory = $true)] [string]$TargetServer,
[Parameter(Mandatory = $true)] [string]$TargetShare,
[Parameter(Mandatory = $true)] [string]$Username,
[Parameter(Mandatory = $true)] [string]$Password
)
Set-StrictMode -Version Latest
$DEPLOY_DRIVE_NAME = "DEPLOY_DRIVE"
# build canonical path to source, target server file share and create user credentials object
$sourceFullPath = (Resolve-Path -LiteralPath $SourcePath).ProviderPath
$targetServerSharePath = Join-Path `
-Path &