ShiftNick

Verify CSV Data

Oct 29th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Import Source CSV
  2. $CSV = Import-CSV -Delimiter "," -Path c:\temp\users.csv
  3.  
  4. #Loop to Create Active Directory Accounts
  5. Foreach ($r in $csv){
  6.  
  7.     #Manager Information
  8.             If( ($($r.MFirst -like "")) -and ($($r.MLast -like "")) ){
  9.                
  10.                 $MGRMess = "No Manager was entered"
  11.                
  12.                 }
  13.                
  14.                 Else{
  15.                      
  16.                      $Mdisplayname = "$($r.MLast)" + ", " + "$($r.MFirst)"
  17.                      $Msam = Get-ADUser -Filter {Name -eq $Mdisplayname} | Select -ExpandProperty SamAccountName
  18.                      
  19.                      If( ($Msam -eq $null) -or ($Msam -eq "") ){
  20.                        
  21.                         $MGRMess = "Could not find $Mdisplayname in Active Directory"
  22.                          
  23.                          }
  24.                          
  25.                          Else{
  26.                            
  27.                             $MGRMess = "Manager is $Mdisplayname/$Msam"
  28.                            
  29.                             }
  30.                     }
  31.  
  32. Write-Output $MGRMess
Advertisement
Add Comment
Please, Sign In to add comment