Reputation: 57
I have the following function to robocopy
(mirror) files from $sourcepath
to $targetPath
and works fine. How will I achieve the same if $targetPath
machine is in another domain?
i.e. sourceServer - Domain1, targetServer - Domain2
function evpcopy {
begin {
#Recommended options
$switchNP = "/NP" #No Progress - don't display percentage copied
#Copy options
$switchMIR = "/MIR" #MIRror a directory tree (equivalent to /E plus /PURGE)
$switchR = "/R:3" #number of Retries on failed copies: default 1 million
$switchW = "/W:1" #Wait time between retries: default is 30 seconds
$sourcePath = '\\sourceServer\d$\EVP'
$targetPath = '\\targetServer\d$\EVP'
#Log File Function
$InputLogFile = 'D:\logs'
if (!(Test-Path -Path $InputLogFile)) {
Write-EventLog -LogName Application -source EvpScript -EventId 1234 -message "path $InputLogFile doesn't exist! `n"
}
$logfile = $InputLogFile + "\" + ((Get-Date).ToString('yyyy-MM-dd')) + "_" + $sourcePath.Split('\')[-1].Replace(" ", "_") + ".txt"
$switchlogfile = "/TEE", "/LOG+:$logfile"
}
process {
$run = robocopy.exe $sourcePath $targetPath $switchNP $switchR $switchW $switchMIR $switchlogfile |
foreach { $ErrorActionPreference = "silentlycontinue" }
}
end {}
} #end robocopy function
evpcopy
Upvotes: 0
Views: 2526
Reputation: 200273
Map the target path to a drive and copy to that drive:
net use X: $targetPath /user:Domain2\username password
robocopy $sourcePath X: ...
net use X: /delete
The last line is to remove the drive after you're finished, so it doesn't keep lingering.
Upvotes: 2