跨域边界的新 PSSession

Mic*_*ens 8 powershell domain credentials

我正在尝试启动一个需要能够创建新会话(使用 New-PSSession)的虚拟机。当然,极具吸引力的about_Remote_Troubleshooting是我的常客

调出基本机器(Win 8.1 Enterprise)后:

  • 例如,我公司的主域是mycompany.com.
  • 我们有一个开发域,dev.mycompany.com因此开发人员可以使用沙箱。
  • 我将新的 VM(名为 my-vm)添加到了开发域dev.mycompany.com
  • 我在新 VM 上有一个本地帐户,该帐户位于my-vm\msorens本地计算机的管理员组中。

第一关:

New-PSSession由于跨域问题,尝试运行失败,访问被拒绝。根据上面引用的故障排除页面:

当另一个域中的用户是本地计算机上 Administrators 组的成员时,该用户无法以管理员权限远程连接到本地计算机。

我不相信这是真的(由于我在领域问题方面缺乏经验),但应用该补救措施的配方允许基本New-PSSession工作:

New-ItemProperty `
-Name LocalAccountTokenFilterPolicy `
-Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System `
-PropertyType DWord `
-Value 1
Run Code Online (Sandbox Code Playgroud)

(虽然安全性较低,但很好,因为它只是一个沙盒虚拟机。)

第二关:

有了上面的补丁,我可以成功地做到以下任何一项:

PS> New-PSSession
PS> New-PSSession -ComputerName localhost
PS> New-PSSession -ComputerName my-vm
Run Code Online (Sandbox Code Playgroud)

但是,我的实际需要是给出机器的 FQDN:

PS> New-PSSession -ComputerName my-vm.dev.mycompany.com
Run Code Online (Sandbox Code Playgroud)

由于缺少凭据而失败。这让我们想到:

PS> New-PSSession -ComputerName my-vm.dev.mycompany.com -Credential (Get-Credential)
Run Code Online (Sandbox Code Playgroud)

我尝试了我的本地(my-vm)凭据,导致WinRM 无法处理请求;没有可用的登录服务器

我已经尝试过我的公司域凭据(请注意,这是 mycompany.com 不是虚拟机实际位于 dev.mycompany.com 上的域),这导致Access is denied

有没有办法使这项工作?

hde*_*dev 9

在工作中,我们也有同样的情况。这是我们在新同事计算机上执行的一些步骤,以便他们能够连接到我们域外的这些服务器。

在客户端

winrm quickconfig
winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'
Run Code Online (Sandbox Code Playgroud)

在服务器端

Enable-PSRemoting -Force
winrm quickconfig
Run Code Online (Sandbox Code Playgroud)

对于 HTTPS

winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="_";CertificateThumbprint="_"}
Run Code Online (Sandbox Code Playgroud)

对于 HTTP

winrm create winrm/config/Listener?Address=*+Transport=HTTP
Run Code Online (Sandbox Code Playgroud)

测试

Test-WsMan ComputerName
Test-WsMan ComputerName -UseSSL
Run Code Online (Sandbox Code Playgroud)

创建一个会话

New-PSSession -ComputerName Computer1 -Credential (Get-Credential)
Run Code Online (Sandbox Code Playgroud)

当然,您需要配置防火墙以让服务器侦听 powershell 远程端口。

编辑:使用 PowerShell 设置 TrustedHosts

或使用 PowerShell(以管理员身份)

Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value "Computer1,Computer2"
Run Code Online (Sandbox Code Playgroud)

并检查(不需要管理员)

Get-Item WSMan:\localhost\Client\TrustedHosts
Run Code Online (Sandbox Code Playgroud)