Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import AD Module
- Import-Module ActiveDirectory
- # Create Date variable for file naming
- $date = (Get-Date).ToString('dd-MM-yyyy-HHmmss')
- # Import CSV in variable $USERS. CSV location and name must exist as in script.
- $USERS = Import-CSV c:\Users\users.csv
- # Loop through CSV and update users if exist or return not found in AD to console and file
- foreach ($user in $USERS){
- try {
- Set-ADUser -Identity $user.sAMAccountname -City $user.City -Department $user.Department -Office $user.Office -OfficePhone $user.OfficePhone -Company $user.Company -Title $user.Title
- }
- catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
- '{0} does not exist in AD' -f $user.SamAccountName | % {write-host $_ ; Add-Content -path C:\Users\setad_$date.txt -value $_} }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement