【问题标题】:PowerShell Enter Session find path bugPowerShell Enter Session 查找路径错误
【发布时间】:2017-08-30 09:57:06
【问题描述】:

我有一些自动化脚本,但我不得不将它们拆分,因为这似乎是一个有趣的错误。我已将其简化为以下最简单的形式:

Enter-PSSession [SERVER]
cd D:\

如果我一次性运行上面的,我会得到以下错误

cd : Cannot find drive. A drive with the name 'D' does not exist.

但是,如果我单独运行这些行,它们运行良好。我试过让睡眠一秒钟,暂停线,但仍然没有运气。有其他人知道这一点,以及解决它的方法吗?

【问题讨论】:

  • Enter-PSSession 专为交互式使用而设计,请勿在脚本中使用

标签: powershell remote-access


【解决方案1】:

使用Invoke-Command 代替enter-pssession

例子:

$ReturnValue = Invoke-Command -ComputerName $Server -ScriptBlock{
    Set-Location D:
    # DO STUFF
    Return $ReturnValue # Return your stuff
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    相关资源
    最近更新 更多