Advertisement
Combreal

getMail.ps1

Sep 22nd, 2020 (edited)
1,907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $cred = Get-Credential -Message "Please enter your DBS login and password" -User $env:USERNAME@ad.dbs.fr
  2. $username = $cred.username
  3. $password = $cred.GetNetworkCredential().password
  4.  
  5. $de = New-Object System.DirectoryServices.DirectoryEntry("LDAP://ad.dbs.fr", $username, $password)
  6.  
  7. $login = $env:USERNAME
  8. $Rech = new-object System.DirectoryServices.DirectorySearcher($de)
  9. $rc = $Rech.filter = "((sAMAccountName=$login))"
  10. $rc = $Rech.SearchScope = "subtree"
  11. $rc = $Rech.PropertiesToLoad.Add("mail");
  12.  
  13. $theUser = $Rech.FindOne()
  14. if ($theUser -ne $null)
  15. {
  16.   Write-Host $theUser.Properties["mail"]
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement