Dre*_*rew 4 powershell robocopy
问题: Robocopy 无法以其他用户身份启动Start-Process
该脚本在具有两个文件位置权限的帐户上运行时运行良好,但它似乎不接受-credential参数。
不确定我的格式是否不正确,或者我做错了什么。
# Create Password for credential
$passw = convertto-securestring "Password" -asplaintext –force
# Assembles password into a credential
$creds = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\Username", $passw
# Select a source / destination path, can contain spaces
$Source = '\\Source\E$\Location'
$Destination = '\\Destination\Location Here'
# formats the arguments to allow the credentials to be wrapped into the command
$RoboArgs = "`"$($Source)`" `"$($Destination)`"" + " /e /Copy:DAT"
# Started Robocopy with arguments and credentials
Start-Process -credential $creds Robocopy.exe -ArgumentList $RoboArgs -Wait
Run Code Online (Sandbox Code Playgroud)
Robocopy 将使用标准的 Windows 身份验证机制。
因此,在发出 robocopy 命令之前,您可能需要使用适当的凭据连接到服务器。
您可以使用它net use来执行此操作。
net use X: '\\Source\E$\Location' /user:MYDOMAIN\USER THEPASSWORD
net use Y: '\\Destination\Location Here' /user:MYDOMAIN\USER THEPASSWORD
net use X: /d
net use Y: /d
Run Code Online (Sandbox Code Playgroud)
然后开始你的 ROBOCOPY
| 归档时间: |
|
| 查看次数: |
11083 次 |
| 最近记录: |