PowerShell连接LDAPS时如何忽略客户端证书弹窗提示?
禁用PowerShell LDAPS匿名绑定的客户端证书选择提示
要解决LDAPS绑定过程中弹出客户端证书选择对话框的问题,你可以通过配置LdapSessionOptions的相关属性,明确指定客户端不提供证书,从而跳过证书选择流程。
修改后的完整代码
[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.Protocols") [System.Reflection.Assembly]::LoadWithPartialName("System.Net") $c = New-Object System.DirectoryServices.Protocols.LdapConnection "dir.mycompany.com:636" # 设置会话选项 $c.SessionOptions.SecureSocketLayer = $true; $c.SessionOptions.ProtocolVersion = 3 # 禁用客户端证书提示的关键配置 $c.SessionOptions.ClientCertificateAuthentication = [System.DirectoryServices.Protocols.ClientCertificateAuthentication]::NoCertificate $c.SessionOptions.ClientCertificates.Clear() $c.AuthType = [System.DirectoryServices.Protocols.AuthType]::Anonymous $c.Bind(); $basedn = "ou=People,dc=mycompany,dc=com" $filter = "(uid=testuser1)" $scope = [System.DirectoryServices.Protocols.SearchScope]::Subtree $attrlist = ,"employeeID" $r = New-Object System.DirectoryServices.Protocols.SearchRequest -ArgumentList $basedn, $filter, $scope, $attrlist $re = $c.SendRequest($r); $re.Entries.count; $re.Entries;
配置说明
- 将
ClientCertificateAuthentication设置为NoCertificate,会让LDAP客户端明确告知服务器不需要使用客户端证书认证,避免系统自动扫描本地可用证书(如智能卡证书)并弹出选择框。 - 调用
ClientCertificates.Clear()是为了清空客户端可能预加载的证书集合,进一步确保不会触发证书选择逻辑。
修改后,即使读卡器中有智能卡,绑定过程也会直接以匿名方式完成,不会再弹出证书选择对话框。
内容的提问来源于stack exchange,提问作者pwky
相关产品推荐
相关产品推荐

