Advertisement
Guest User

Untitled

a guest
Nov 19th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Import AD Module
  2.  
  3. Import-Module ActiveDirectory
  4.  
  5. # Create Date variable for file naming
  6.  
  7. $date = (Get-Date).ToString('dd-MM-yyyy-HHmmss')
  8.  
  9. # Import CSV in variable $USERS. CSV location and name must exist as in script.
  10.  
  11. $USERS = Import-CSV c:\Users\users.csv
  12.  
  13. # Loop through CSV and update users if exist or return not found in AD to console and file
  14.  
  15. foreach ($user in $USERS){
  16.  
  17. try {
  18.  
  19. Set-ADUser -Identity $user.sAMAccountname -City $user.City -Department $user.Department -Office $user.Office -OfficePhone $user.OfficePhone -Company $user.Company -Title $user.Title
  20.  
  21. }
  22.  
  23. catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
  24.  
  25. '{0} does not exist in AD' -f $user.SamAccountName | % {write-host $_ ; Add-Content -path C:\Users\setad_$date.txt -value $_} }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement