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.
./remotecopy.ps1 `
-SourcePath "." `
-TargetServer "localhost" -TargetShare "myshare" `
-Username "USERNAME" -Password "PASSWORD"
Copied files from [C:\scripts\myfiles] to [\\localhost\myshare]
Deleted orphan directory [\\localhost\myshare\blurg]
Deleted orphan file [\\localhost\myshare\old-file.txt]