rsc*_*rin 4 powershell powershell-2.0 microsoft-bits
如何在不同域的服务器之间传输文件?
i.e
PS C:\Users\Desktop> Import-Module bitstransfer
PS C:\Users\Desktop> $c=get-credential
PS C:\Users\Desktop> start-bitstransfer -Credential $c -source \\server\c$\test.txt -destination .
Run Code Online (Sandbox Code Playgroud)
输出是:
Start-BitsTransfer : Cannot find path '\\server\c$\test.txt' because it does not exist.
Run Code Online (Sandbox Code Playgroud)
我有权探索该服务器,但我无法使用BitsTransfer.
它只有在我将\ server\c $作为共享挂载时才有效(即使用"net use"命令),但我想逃避它.
谢谢
根据我的发现,我认为问题在于BitsTransfer的工作方式.它只能以交互方式工作(即作为登录和活动用户).来自Microsoft的文档:
在非交互式上下文(例如Windows服务)中运行的进程中使用*-BitsTransfer cmdlet时,可能无法将文件添加到BITS作业,这可能导致挂起状态.要继续执行作业,必须登录用于创建传输作业的标识.例如,在作为任务计划程序作业执行的PowerShell脚本中创建BITS作业时,除非启用任务计划程序的任务设置"仅在用户登录时运行",否则BITS传输将永远不会完成.- 使用Windows PowerShell创建BITS传输作业
在我做了一些测试之后,这意味着问题不在于跨域身份验证(我假设你有正确的信任等工作),而是Bits使用登录进行身份验证.
因此,我们得到以下类型的问题(使用没有访问权限的contoso\user和contoso/admin谁)并指定凭证参数:
现在尝试一些runas变通办法.以contoso\user身份登录时:
runas /user:contoso\admin powershell.exe 跑了Start-BitsTransfer = Error: Start-BitsTransfer : The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (Exception from HRESULT: 0x800704DD)
-Credential相同的结果.做一个runas就像你以其他用户身份登录,但我想你可能需要一个配置文件......让我们尝试下一步.runas /profile /user:contoso\admin powershell.exe 跑了Start-BitsTransfer = Error: Start-BitsTransfer : The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (Exception from HRESULT: 0x800704DD)
runas /netonly /user:contoso\admin powershell.exe 跑了Start-BitsTransfer = Error: Start-BitsTransfer : Access is denied.
最后,到解决方法.如下:
$c = Get-Credential -UserName 'consoso\admin'
net use \\server\c$
Start-BitsTransfer -Credential $c -source \\server\c$\test.txt -destination .
#Success
net use \\server\c$ /delete
#Error: Cannot find path
Run Code Online (Sandbox Code Playgroud)
(当然使用contoso\admin作为net use命令)
原因是net use命令实际上会将您登录到服务器上.一旦你有了kerberos票,它就可以了,因为它已经缓存了管理员凭证,并使用它们来访问该文件.有关类似的解决方案,请参阅:copy-item With Alternate Credentials
基本上,它看起来像Bits转移有一个错误,它不会-Credential按预期处理该属性.相反,它似乎总是默认使用当前登录的用户进行身份验证,除了您手动执行net use命令以自己手动形成连接.
| 归档时间: |
|
| 查看次数: |
6574 次 |
| 最近记录: |