Powershell - Import User CSV ignore blanks fields

Am trying to import a group of users into powershell - I need to skip some empty fields.  I believed that "" would ignore that field but when I go to AD it actually imports the "".  Any suggestions please.
BYRONJACKSONAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

becraigCommented:
Import-Csv file.csv |? { ($_.PSObject.Properties | % {$_.Value}) -ne $null}

Open in new window

0
BYRONJACKSONAuthor Commented:
cool - will this verify all entries? sorry new to Powershell have over 1000 users to amend
0
BYRONJACKSONAuthor Commented:
Bascially if I enter null as the value it will import null - if the field is blank I get this error.


Set-ADUser : replace
At line:14 char:3
+   Set-ADUser -Description $($user.Description) -Office $($user.Office) -GivenNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (CN=adamtest4,OU...erange,DC=local:ADUser) [Set-ADUser], ADInvalidOperationException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

becraigCommented:
So you want to filter out where ANY column is blank ?

e.g 5 columns have data  but the sixth does not etc  ?
0
BYRONJACKSONAuthor Commented:
Yes that is correct - although in some cases there several attributes for users that appear for some but not all users.  So we kind of want something that can sort through each column and add entries where necessary and non entries should appear blank in AD.  Hope this makes sense?

Byron
0
becraigCommented:
Ok so the easiest way I can think of would be a where statement using all the columns or an if statement after the import.

Either would require the names of all the columns in the csv beforehand
(The smarter guys here might have a better approach)
import-csv file.csv | ? {$_.value1 -ne $null -and $_value2 -ne $null -and $_.value3 -ne $null}

Open in new window

OR

import-csv file.csv | % {
if ($_.value1 -ne $null -and $_value1 -ne '' -and $_.value2 -ne $null -and $_value2 -ne '' -and $_.value3 -ne $null -and $_.value3 -ne '')
{#Do something}
}

Open in new window

0
BYRONJACKSONAuthor Commented:
Thank you will give that a go shortly ... out of interest and for my own learning what does the % represent in the above.
0
becraigCommented:
It means foreach object
? means where object
0
BYRONJACKSONAuthor Commented:
Thank you very much for that  - will modify what I have and see how I get on. Will let you know soon as

Byron
0
becraigCommented:
Np hope it helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BYRONJACKSONAuthor Commented:
Thank you so much! Really helped me out :-)
0
BYRONJACKSONAuthor Commented:
Thank you so much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.