【问题标题】:Mapping drive on a remote machine in powershell在 powershell 中映射远程机器上的驱动器
【发布时间】:2013-06-21 14:47:07
【问题描述】:

我正在从我的桌面上使用远程计算机,并且我有以下脚本:

Invoke-Command -computername $name -authentification default -凭据 $creds1 -scriptblock {net use \share $password2 /user:otherdomain\otheruser}

然后我得到一个指定的登录会话不存在。它可能已经被终止。这件事令人沮丧,因为如果我直接在远程机器上运行net use \\share $password2 /user:otherdomain\otheruser,它就可以完美运行。有解决方法还是我错过了什么?

【问题讨论】:

  • 我通过将 net session 添加到我的远程脚本中发现没有条目。有人知道如何手动添加吗?

标签: powershell mapping net-use


【解决方案1】:

你需要将变量$password2传递到脚本块中,否则它的值为空:

Invoke-Command -Computer $name ... -ScriptBlock {
  net use \\host\share $args[0] /user:otherdomain\otheruser
} -ArgumentList $password2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    相关资源
    最近更新 更多