繁体   English   中英

从 Azure 云中 Windows Server 上运行的 Active Directory 获取用户

[英]Get Users from Active Directory running on Windows Server in Azure Cloud

我想读出在蔚蓝云中的 Windows Server 2016 上运行的活动目录中的所有用户。 我可以使用远程桌面访问 Windows 服务器,但我无法使用 DirectoryServices 的 PrincipalContext 连接到 AD。 我有运行 Active Directory 服务的远程 Windows Server 2016 的 IP 地址。 还创建了具有管理员权限的用户。

我尝试了有关 PrincipalContext 连接的不同陈述。

1.

using (var adContext = new PrincipalContext(ContextType.Domain, "ip-adress of remote server"))
using (var adContext = new PrincipalContext(ContextType.Domain, "LDAP://ip-adress of remote server"))
 using (var context = new PrincipalContext(ContextType.Domain, "ip-adress of remote server", "CN=Users", "adminuser", "adminpassword")

我得到的例外是 System.DirectoryServices.AccountManagement.PrincipalServerDownException: '无法联系服务器。 是否存在问题,因为服务器不在同一个域中?

这是我第一次对活动目录或 Windows 服务器做任何事情。 因此,如果我的方法中有一些巨大的错误,请体谅。

听起来像是防火墙问题 - 您只是无法通过网络联系服务器。 您可以使用以下命令在 PowerShell 中对此进行测试:

Test-NetConnection "ip-adress of remote server" -Port 389

您可以测试 4 个端口:

  • 389:默认的 LDAP 端口。 如果您未指定端口,则使用此选项。
  • 636:LDAPS 或 LDAP over SSL(加密)
  • 3268:全局目录。 工作方式与 LDAP 相同,但包括林中的所有域(如果您有多个域)
  • 3269:基于 SSL 的垃圾回收

如果任何其他端口工作,那么您可以在PrincipalContext指定它:

new PrincipalContext(ContextType.Domain, "ip-adress of remote server:636")

使用 SSL 会使事情变得有点复杂,因为您的计算机需要信任服务器发送的 SSL 证书。

如果所有端口都不起作用,则说明某处有防火墙阻止了通信,您需要先修复该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM