SHARE
TWEET

Untitled

a guest Nov 6th, 2018 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #**********************************************************************
  2. # Test-LDAPConnectivity.ps1
  3. # This script is designed to Test the connectivity to LDAP, wether it is Open LDAP or Active Directory
  4. # Author: Mike Burr
  5. # Modified On: 29-SEP-2016
  6. # Modifed By: Harmik Singh Batth
  7. # Version: 1.0
  8. # Change History:
  9. #
  10. #
  11. #**********************************************************************
  12.  
  13. Function Test-LdapConnectivity
  14. {
  15. param(
  16. [String]$ServerName = "srvfs01.eibiswald.local",
  17. [UInt16]$Port = 389,
  18. [String]$UserName = "ittgast",
  19. [String]$Password = "Kennwort1"
  20. )
  21. #Main script
  22. Clear-host
  23.  
  24. #Check if all arguments are passedd
  25. if (!$serverName -or !$Port -or !$UserName -or !$Password)
  26. {
  27. Write-Host "USAGE: Test-LDAPConnectivity.ps1 ServerName Port UserName Password"
  28. write-host "Paramaters not defined properly, script will exit now"
  29. break
  30. }
  31.  
  32. if (!$serverName) {write-host "Please define Server Name"}
  33. if (!$Port) {write-host "Please define Port"}
  34. if (!$UserName) {write-host "Please define Username"}
  35. if (!$Password) {write-host "Please define Password"}
  36.  
  37. #Load the assemblies
  38. [System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.Protocols")
  39. [System.Reflection.Assembly]::LoadWithPartialName("System.Net")
  40.  
  41. #Connects to Server on the standard port
  42. $dn = "$ServerName"+":"+"$Port"
  43. $c = New-Object System.DirectoryServices.Protocols.LdapConnection "$dn"
  44. $c.SessionOptions.SecureSocketLayer = $false;
  45. $c.SessionOptions.ProtocolVersion = 3
  46.  
  47. # Pick Authentication type:
  48. # Anonymous, Basic, Digest, DPA (Distributed Password Authentication),
  49. # External, Kerberos, Msn, Negotiate, Ntlm, Sicily
  50. $c.AuthType = [System.DirectoryServices.Protocols.AuthType]::Basic
  51.  
  52. $credentials = new-object "System.Net.NetworkCredential" -ArgumentList $UserName,$Password
  53.  
  54. # Bind with the network credentials. Depending on the type of server,
  55. # the username will take different forms. Authentication type is controlled
  56. # above with the AuthType
  57. Try
  58. {
  59.  
  60. $c.Bind($credentials);
  61. Write-Verbose "Successfully bound to LDAP!" -Verbose
  62. return $true
  63. }
  64. catch
  65. {
  66. Write-host $_.Exception.Message
  67.  
  68. return $false
  69. }
  70.  
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top