如何在不同域的 2 个服务器之间自动复制文件夹?
How to robocopy folder between 2 servers in different domains?
我有以下功能可以从 $sourcepath
到 $targetPath
robocopy
(镜像)文件并且工作正常。如果 $targetPath
机器在另一个域中,我将如何实现相同的目标?
即源服务器 - 域 1,目标服务器 - 域 2
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
将目标路径映射到驱动器并复制到该驱动器:
net use X: $targetPath /user:Domain2\username password
robocopy $sourcePath X: ...
net use X: /delete
最后一行是完成后删除驱动器,所以它不会一直挥之不去。
我有以下功能可以从 $sourcepath
到 $targetPath
robocopy
(镜像)文件并且工作正常。如果 $targetPath
机器在另一个域中,我将如何实现相同的目标?
即源服务器 - 域 1,目标服务器 - 域 2
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
将目标路径映射到驱动器并复制到该驱动器:
net use X: $targetPath /user:Domain2\username password
robocopy $sourcePath X: ...
net use X: /delete
最后一行是完成后删除驱动器,所以它不会一直挥之不去。