Active Directory
A set of directory-based technologies included in Windows Server.
6,642 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have a web server in a DMZ, and want to test a secure LDAP connection to the non-DMZ domain using alternate credentials. Is there a way to get Powershell to prompt for credentials with the [adsi] command?
I would like to be able to run [adsi]"LDAP://myadserver.mydomain.local:636" and have it prompt for user credentials. So far I am not having any luck.
Thanks for any help
Try either of these:
$user = Read-Host "User: "
$password = Read-Host "Password: "
$ADSI = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$OUPath", $username, $password)
$cred = Get-Credential
$ADSI = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$OUPath", $cred.UserName, $cred.GetNetworkCredential().Password
)
Hello there,
You can use Test-LDAP to verify whether LDAP and LDAPS are available on one or more Domain Controllers.
Function Test-LDAPConnection {
[CmdletBinding()]
# Parameters used in this function
Param
(
[Parameter(Position=0, Mandatory = $True, HelpMessage="Provide domain controllers names, example DC01", ValueFromPipeline = $true)]
$DCs,
[Parameter(Position=1, Mandatory = $False, HelpMessage="Provide port number for LDAP", ValueFromPipeline = $true)]
$Port = "636"
)
$ErrorActionPreference = "Stop"
$Results = @()
Try{
Import-Module ActiveDirectory -ErrorAction Stop
}
Catch{
$_.Exception.Message
Break
}
ForEach($DC in $DCs){
$DC =$DC.trim()
Write-Verbose "Processing $DC"
Try{
$DCName = (Get-ADDomainController -Identity $DC).hostname
}
Catch{
$_.Exception.Message
Continue
}
If($DCName -ne $Null){
Try{
$Connection = [adsi]"LDAP://$($DCName):$Port"
}
Catch{
$ExcMessage = $_.Exception.Message
throw "Error: Failed to make LDAP connection. Exception: $ExcMessage"
}
If ($Connection.Path) {
$Object = New-Object PSObject -Property ([ordered]@{
DC = $DC
Port = $Port
Path = $Connection.Path
})
$Results += $Object
}
}
}
If($Results){
Return $Results
}
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer--