Advertisement
Combreal

getMailUserFromGTPIImport.ps1

Sep 23rd, 2019
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $FirstName = @()
  2. $LastName = @()
  3. $liny = ""
  4. foreach($line in Get-Content .\userList.txt) #.\userList.txt
  5. {
  6.     $UC = ""
  7.     $LC = ""
  8.     $strtab = $line -split "\s+"
  9.     for($i=0; $i -lt $strtab.length; $i++)
  10.     {
  11.         if($strtab[$i] -cmatch "[A-Z]{2,}")
  12.         {
  13.             if($UC -eq "")
  14.             {
  15.                 $UC = $strtab[$i]
  16.             }
  17.             else
  18.             {
  19.                 $UC += " " + $strtab[$i]
  20.             }
  21.         }
  22.         else
  23.         {
  24.             if($LC -eq "")
  25.             {
  26.                 $LC = $strtab[$i]
  27.             }
  28.             else
  29.             {
  30.                 $LC += " " + $strtab[$i]
  31.             }
  32.         }
  33.     }
  34.     $FirstName += $LC
  35.     $LastName += $UC
  36. }
  37. #0..($FirstName.Length-1) | Select-Object @{n="FirstName";e={$FirstName[$_]}}, @{n="LastName";e={$LastName[$_]}}  #display 2 dim tab of name & surname
  38. for($i=0; $i -lt ($FirstName.Length-1); $i++)
  39. {
  40.     $theUser = Get-ADUser -SearchBase "ou=SAM,dc=mydom,dc=dom,dc=fr" -Properties mail -Filter * `
  41.     | ? { $_.SurName -eq $LastName[$i] -and $_.GivenName -eq $FirstName[$i]} | select -Property mail, GivenName, Surname
  42.     $liny += $theUser.mail + " " + $theUser.GivenName + " " + $theUser.SurName + "`n"
  43. }
  44. $liny | Out-File ".\userListFormated.txt"
  45. $liny
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement