在Centos 7上使用PowerShell 6.0.2版本,尝试将会话获取到Windows 2012 Server。执行以下操作:
$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("domainusername", $secpasswd)
Enter-PSSession -ComputerName Some-Host-Name -port 5985 -Credential $mycreds
获得以下错误:
Enter-PSSession : MI_RESULT_ACCESS_DENIED At line:1 char:2
+ Enter-PSSession -ComputerName Some-Host-Name -port 5985 -Credential $m ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Some-Host-Name :String) [Enter-PSSession], PSInvalidOperationException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
应该获取到Windows计算机的会话。
按顺序完成以下操作Windows机器将信任centos机器
Set-Item WSMAN:LocalhostClientTrustedHosts -Value * -Force
有什么想法我需要做什么吗?
从Linux到Windows的远程处理需要使用SSH。这在MS文档网站上有介绍。
SSH 上的PowerShell远程处理
概述
PowerShell远程处理通常使用WinRM进行连接协商数据传输。SSH被选择用于此远程处理实现,因为它现在可用于Linux和Windows平台,并允许真正的多平台PowerShell远程处理。但是,WinRM也提供了PowerShell远程会话的健壮托管模型实现还没有实现。这意味着PowerShell远程端点配置和JEA(Just Enough Administration(还没有在该实现中得到支持。
https://learn.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core?view=powershell-6
Windows、Mac和Linux上的PowerShell核心入门我需要吗?
若要开始使用要安装和配置的PowerShell Core您选择的操作系统上有以下三项:•PowerShellCore 6 Beta•OpenSSH•Visual Studio Code
我很惊讶我能如此迅速地跟上安装说明。每个过程涉及的相对较少为测试版体验进行调整。
如果你是一个Linux用户,你可能会想,"好吧,我已经有了已安装OpenSSH。"请阅读上面的OpenSSH链接,了解步骤编辑sshd_config文件以获得PowerShell远程处理支持。
https://blogs.msdn.microsoft.com/powershell/2017/06/09/getting-started-with-powershell-core-on-windows-mac-and-linux
或者也可以看到这些答案:
从Linux终端管理Windows Powershell
https://serverfault.com/questions/638659/managing-windows-powershell-from-linux-terminal
如何设置Linux以查询Windows WinRM主机
http://www.tomsitpro.com/articles/setup-linux-to-query-windows-winrm-hosts,1-3468.html