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

csv import to set-aduser properties skipping empty fields/whitespace

$
0
0

So I have a question about importing a csv and avoiding empty cells/fields. 

We are planning on doing a data dump from one database into a csv then use that information to populate user information in AD. 

I've gotten it to write correctly to AD by doing:

$csv = Import-Csv "C:\Users\Administrator\Desktop\userlist1.csv"

foreach($user in $csv){

Set-ADUser -Identity $_.Name -GivenName $_.First .... etc}

and 

Import-Csv "C:\Users\Administrator\Desktop\userlist1.csv" | foreach-object {Set-ADUser -Identity $user.Name -GivenName $user.First .... etc}

Either way worked, the only problem I'm having is with some empty cells in the csv file. Like for example, some users have company issued cell phones, while others don't, well the ones that don't, the script bombs out and seems to do nothing to their user account. There are some other things that might be empty not just cell fields.  

Now I'm by no means a pro with powershell but i'm trying to learn, so is there any more efficient/better way to do what I'm trying to do? Sync user information from a CSV file to AD skipping the white spaces or empty cells/fields? Also there are column headers in the csv file.


Viewing all articles
Browse latest Browse all 6937

Trending Articles