Link to home
Start Free TrialLog in
Avatar of Pete
PeteFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell - check csv format

Hello I want to import a users.csv to create new AD users but I want to check its in the correct format first, how can I do this in powershell? Checking correct column headings, maybe also checking the entire contents not containing illegal characters like hyphens, apostrophes etc..

Any advice please?
Avatar of Niten Kumar
Niten Kumar
Flag of Fiji image

What is the format of your csv file?  Best would be if you use a proper template where the required data is input correctly then there should be no issues.  See attached .xls file.  You can modify it to your requirements.  The instructions are on the first sheet.
MassUserCreationScriptSource.xls
Avatar of Pete

ASKER

That is not the answer to the question, I know what a properly formatted csv should look like, I want to script in some protection in case it is wrong.
What Niten is suggesting, and I'll second, is that Powershell might not be the best tool for doing this 'validation'.  You are going to have to read each line from the CSV file, and then perform custom checks on it, based on your own needs, like not allowing certain characters, checking length, if each element is supplied, etc.

It might be easier and more efficient to perform these checks before the file is created.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial