user1195370
user1195370

Reputation: 11

Powershell import CSV with multiple delimiters

I've got a CSV that has multiple delimiters and the following format: groupname;user1,user2;user3 groupname;user1,user2;user3,users4

How can i add the users to the AD groups. All the group names in the CSV ends with an ";" seperator and the users users use the "," seperator.

Upvotes: 0

Views: 3990

Answers (3)

Jo Ann Guest
Jo Ann Guest

Reputation: 1

What about :

Import-Csv -Path $inputfile -Delimiter ';' |  export-csv $outfile -Delimiter ',' -NoClobber -NoTypeInformation 
Import-Csv -Path $outfile -Delimiter ','

First take in with ; then export that with , and then take the whole bunch in as a , separtated file.

Upvotes: 0

mjolinor
mjolinor

Reputation: 68341

That's a going to make a jagged array if you try to split it at the ; and then split the member list at the commas during the import. It will be difficult to get imported as .csv because you won't have a consistent number of elements in each record.

I'd do the import-csv using the ; as the delimiter, and then split the member list at the commas when it's time to add the members.

Upvotes: 1

Jeffery Hicks
Jeffery Hicks

Reputation: 943

Does the header and data still match up, even with different delimiters? If so, I'd replace the odd delimiter with a comma and then to the import. Unless the file is enormous, I'd simply make a clean, second copy and import that.

Upvotes: 0

Related Questions