【发布时间】:2022-11-30 05:05:32
【问题描述】:
这是家庭作业的一部分。作为管理脚本的一部分,其中一项任务是使用脚本中的预设凭据在远程计算机上打开交互式 Powershell 提示符。从常规交互式 shell 打开一个工作正常,但是从脚本打开一个已被证明是困难的。
我尝试了以下方法:
$password = ConvertTo-SecureString -String "password" -AsPlainText -Force`
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username", $password
$session = New-PSSession -Credential $credentials -ComputerName "remote-computer"
Enter-PSSession -Session $session
从交互式 shell 执行此操作按预期工作并在远程计算机上生成交互式提示,但是从脚本执行此操作会导致 shell 无响应,因为它需要脚本的进一步输入。
如果我在进入远程 Powershell 会话后尝试 Start-Process -Wait -NoNewWindow -FilePath "powershell" 或告诉 Start-Process 通过 cmd.exe 执行 Powershell,它会打开一个本地实例。
【问题讨论】:
标签: powershell remote-access remote-server interactive-shell