Combreal

getMail.ps1

Sep 22nd, 2020
1,125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $cred = Get-Credential -Message "Please enter your INRIA login and password" -User $env:USERNAME@ad.inria.fr
  2. $username = $cred.username
  3. $password = $cred.GetNetworkCredential().password
  4.  
  5. $de = New-Object System.DirectoryServices.DirectoryEntry("LDAP://ad.inria.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.  
RAW Paste Data