通过 PowerShell Remote 获取 DHCPServerinDC

问题描述 投票:0回答:2

我有多个 Active Directory 林,并且我想为每个林获取授权的 DHCP 服务器。我想调用 PowerShell CmdLet

Get-DHCPServerinDC
。如果我在林 A 中的域控制器上执行该命令,它将输出正确的 DHCP 服务器。如果我从林 B 通过
Invoke-Command -ComputerName DCforestA -ScriptBlock {Get-DHCPServerinDC}
执行命令,我会从林 B 获得授权的 DHCP 服务器。 这是一个错误吗?谁能重现这个问题吗?

windows powershell active-directory
2个回答
0
投票

我在这里发帖是因为这个问题很老了,但是在这里找到答案比在 ServerFault 上找到等效问题更容易:)

我刚刚遇到了同样的问题,看起来该问题是由于 cmdlet 从用户帐户获取要执行的域所致。这在一定程度上是有意义的,不过如果 cmdlet 具有域感知能力并能够接受域作为参数就更好了。

如果您传递要执行命令的远程域的凭据,则会检索正确的服务器列表。在下面的示例中,您位于域 1 上的计算机上,并连接到域 2 上的服务器 1:

$cred=Get-Credential -Message "Enter credentials for an account on domain2";
Invoke-Comand -Computername server1 -Credential $cred -Scriptblock {Write-Host $env:USERDOMAIN;Get-DCHPServerInDC}

打印 USERDomain 环境变量以确认脚本块正在执行的上下文。


0
投票

这里有一个拼写错误,命令是:Invoke-Command

$cred=Get-Credential -Message“输入域 2 上帐户的凭据”; 调用命令 -Computername server1 -Credential $cred -Scriptblock {Write-Host $env:USERDOMAIN;Get-DCHPServerInDC}

© www.soinside.com 2019 - 2024. All rights reserved.