Hello, i have an issue with a script to import and update a list of current user details in AD
Posted on 2014-09-03
I have a csv file that has been exported from our AD, I have amended and added details and can re-import a sample few back into a test environment, however I have come across an issue where any blank cells in the csv file cause the script to fall over.
is there a way I can get my script to skip or ignore any blank cells it comes across, change the value to empty if needed and continue?
here is what I have so far which works fine if all csv cells have information in them.
# Import AD Module
# Import CSV into variable $userscsv
$users = Import-Csv -Path c:\users\aflook\desktop\NewUsers1.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 “ou=Adam Test,DC=therange,DC=local" |
Set-ADUser -Description $($user.Description) -Office $($user.Office) -GivenName $($user.GivenName) -SurName $($user.SurName) -DisplayName $($user.DisplayName) -PostalCode $($user.postalCode) -mobile $($user.mobile) -Company $($user.company) -StreetAddress $($user.StreetAddress) -City $($user.City) -OfficePhone $($user.OfficePhone) -Title $($user.Title) -Department $($user.Department) -Fax $($user.Fax) -State $($user.State) -HomePage $($user.HomePage) }