powershell - 通过 ssh 进行的 Powershell 会话。开始工作
问题描述
我编写脚本以使用 PowerShell 远程控制 WindowsDefender。这是我第一次见到PS。我所拥有的:我有 Ubuntu 并在其上安装了 PS (v. 7) 客户端。我通过 ssh 设置 PS 会话到远程 Win10 机器。我尝试使用不同的命令,一切正常。
但我不明白接下来:
Terminal1:我打开了会话:
$session = New-PSSession -HostName user@host -KeyFilePath /home/user/.ssh/id_rsa
Id Name Transport ComputerName ComputerType State ConfigurationName
2 Runspace1 SSH host RemoteMachine Opened De…
接下来我开始扫描WinDef:
Invoke-Command -Session $session -ScriptBlock {start-mpscan -asjob}
并从 ms 示例开始简单的后台作业
Invoke-Command -Session $session -ScriptBlock {Start-Job -ScriptBlock { Get-Process -Name pwsh }}
我可以得到所有的工作:
Invoke-Command -Session $session -ScriptBlock {get-job}
Id Name PSJobTypeName State HasMoreData Location Command PSComputerName
2 Job2 RemoteJob Completed True localhost param($name, $boundPara… host
4 Job4 BackgroundJob Completed True localhost Get-Process -Name pwsh host
但是,如果我离开此会话或尝试连接到同一主机,我将无法开始我的工作。我的 MS 文档说(如果我理解正确的话)会话在远程机器上打开,我可以回到它。我想早点开始工作以停止这项工作。
我尝试使用命令Enter-PSSession
- 相同。
对于我的 linux pwsh 客户端,某些命令不起作用,例如
Connect-PSSession: The term 'Connect-PSSession' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我很困惑。
我做错了什么?我怎样才能打开会话?我使用了错误的命令吗?还是我应该做一些设置并设置权限?
解决方案
推荐阅读
- scala - 来自 Join 的嵌套对象
- javascript - 如何在表数据中通过 javaScript 使用“按日期排序”?
- node.js - 无法将数据从角度发布到节点 api
- jekyll - 待办事项列表在 GitHub 页面上呈现不同
- python - 为什么 numpy 没有出现在我的 virtualenv 中的 pip3 列表中,即使我在两秒前安装了 pip3 install numpy ?
- reactjs - Reactjs 网络应用程序谷歌地图在 PC 本地主机上工作但在移动设备上不工作
- amazon-web-services - 请求私有证书被禁用:怎么会?
- laravel - 如何在 laravel 的单个控制器中传递多条路由
- google-apps-script - 如何每次在 Google Apps 脚本中正确使用 LockService?
- python - Python ZeroDivisonError 我该如何解决这个问题?