Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Updating AD User properties from users.csv

$
0
0

I have been working on a script that has been working perfectly like it is supposted to to update AD User properties from a csv spreadsheet,

Then I added a new line for a new users and it gave an error that i cant even fined any info on on Google.  acts as if it doesnt like the new name.

Here is my script:

# Import AD Module            
Import-Module ActiveDirectory           

write-Host 'Starting to update AD Attributes.......' -NoNewline -ForegroundColor Yellow           
# Import CSV into variable $users          
     
$users = Import-Csv -Path C:\temp\Users.csv           
# Loop through CSV and update users if the exist in CVS file           
           
foreach ($user in $users) {           
#Search in specified OU and Update existing attributes           
 Get-ADUser -Filter "samaccountname -eq '$($user.samaccountname)'" -Properties * -SearchBase "DC=corp,DC=letsfish,DC=com"|           
  Set-ADUser -GivenName $($user.Firstname) -Surname $($user.Lastname) -DisplayName $($user.DisplayName) -Title $($user.JobTitle) -MobilePhone $($user.MobilePhone) -OfficePhone $($user.OfficePhone) -Street $($user.Street) -City $($user.City) -State $($user.State) -PostalCode $($user.PostalCode) -EmailAddress $($user.EmailAddress) -Department $($user.Department) -Office $($user.Office) -Manager $($user.Manager) -Company $($user.Company) -Country $($user.Country) -Description $($user.Description)
       
}

Write-Host 'done!' -ForegroundColor Green

 

 

Starting to update AD Attributes.......Set-ADUser : replace
At C:\Users\gdrews\Desktop\Update-ADattributes\Update-ADattributes-from-CSV.PS1:24 char:13
+   Set-ADUser <<<<  -GivenName $($user.Firstname) -Surname $($user.Lastname) -DisplayName $($user.DisplayName) -Title
$($user.JobTitle) -MobilePhone $($user.MobilePhone) -OfficePhone $($user.OfficePhone) -Street $($user.Street) -City $($
user.City) -State $($user.State) -PostalCode $($user.PostalCode) -EmailAddress $($user.EmailAddress) -Department $($use
r.Department) -Office $($user.Office) -Manager $($user.Manager) -Company $($user.Company) -Country $($user.Country) -De
scription $($user.Description)
    + CategoryInfo          : InvalidOperation: (CN=Chase Lamour...strominc,DC=com:ADUser) [Set-ADUser], ADInvalidOper
   ationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

done!


Viewing all articles
Browse latest Browse all 6937

Trending Articles