I have a script to update user attributes by fetching them from a csv file. However it gives me below mentioned error on every attribute. Please help.
ERROR:
======================================================================================================
Set-ADUser : Cannot find an object with identity: '' under: 'DC=parco,DC=com,DC=pk'.At C:\Users\zeeshan.opel\Desktop\UserUpdate.ps1:27 char:5+ Set-ADUser -Identity "$ADUser" -Replace @{postOfficeBox=$POBox}+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (:ADUser) [Set-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.Activ eDirectory.Management.Commands.SetADUser
SCRIPT:
# Import AD Module Import-Module ActiveDirectory # Import User Details from CSV $users = Import-Csv -Path C:\users.csv # Get Values from CSV in Seperate Variables foreach ($user in $users) { $Acc = $users.samaccountname $ID = $users.employeeID $Company = $users.company $Grade = $users.grade $Title = $users.title $Division = $users.division $Department = $users.department $City = $users.city $POBox = $users.pobox
# Find out of user from domain id $ADUser = Get-ADUser -Filter "samaccountname -eq '$Acc'"# Set user properties according to DN Set-ADUser -Identity "$ADUser" -Replace @{employeeID=$ID} Set-ADUser -Identity "$ADUser" -Replace @{title=$Title} Set-ADUser -Identity "$ADUser" -Replace @{division=$Division} Set-ADUser -Identity "$ADUser" -Replace @{company=$Company} Set-ADUser -Identity "$ADUser" -Replace @{department=$Department} Set-ADUser -Identity "$ADUser" -Replace @{l=$City} Set-ADUser -Identity "$ADUser" -Replace @{postOfficeBox=$POBox} }