exclude quotation mark while powershell a CSV file

hello experts
my example CSV file is below
group,owner
group1,"alice,bob"
group2,"jack,david"

while i call the CSV file via powershell, it with quotation mark so that command can't recognize it, my question is how to exclude the quotation mark while i running command with call such CSV file.

thank you
beardog1113Asked:
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.

Prashant GirennavarCommented:
May be simple solution to this is to remove the quotation mark in a csv file.

Just open up the CSV file and do a cntl+h (Find and replace funtion), replace "" mark with nil , so that the file have no quotation ,

Then try calling csv.....

Thanks,

-Prashant Girennavar.
0
beardog1113Author Commented:
hello
what is nil as you mentioned?
or what will the CSV file looks like from my example?

thank you
0
oBdACommented:
Please describe your problem more precisely. Powershell has no problems importing a csv with mixed quoted and non-quoted fields. The resulting properties will be stripped of surrounding quotes.
PS C:\Temp> Get-Content .\TestQuotes.csv
group,owner
group1,"alice,bob"
group2,"jack,david"
PS C:\Temp> Import-Csv .\TestQuotes.csv | ft -au

group  owner
-----  -----
group1 alice,bob
group2 jack,david


PS C:\Temp> (Import-Csv .\TestQuotes.csv)[0].Owner
alice,bob
PS C:\Temp>

Open in new window

1
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

beardog1113Author Commented:
hello oBdA
i am using Microsoft online module of powershell to do the managing work, for example
Import-Csv c:\test.csv | %{Set-DistributionGroup -Identity $_."group" -ManagedBy $_.owner}
i will get error it will same can't not found "alice,bob", that is because there is quotation mark at begin and end of owner column, if i try configure it for an individual group, without any problem, for example:
Set-DistributionGroup -Identity group1 -ManagedBy alice,bob
hope you understand what i am meaning.

thank you
0
oBdACommented:
That is a different issue and has nothing to do with the quotes surrounding the fields.
When you enter ... -ManagedBy alice,bob in a command line, you're passing a list consisting of 2 entries ("alice" and "bob") for the "ManagedBy" argument, so Powershell will look for two separate accounts "alice" and "bob".
Now you're pulling the string "alice,bob" from the csv and pass it to "ManagedBy", so Powershell tries to find an account named "alice,bob", which will fail.
Since you defined the format of the "Owner" field yourself (as a comma separated list of accounts - which is the information that was missing in your question), you have to evaluate the content yourself as well when passing it to a cmdlet:
Import-Csv c:\test.csv | % {Set-DistributionGroup -Identity $_."group" -ManagedBy ($_.owner).Split(',')}

Open in new window

1

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
beardog1113Author Commented:
hello oBdA
thats great your example fixed my issue, could you also explain how ($_.owner).Split(',') exclude the quotation mark from the CSV file then into cmdlet?

thank you
0
beardog1113Author Commented:
that s great, thank you
0
oBdACommented:
Again: this has nothing to do with the quotation marks in the csv file.
When importing a csv, all fields are imported as string (because PS has no knowledge which type a field could have). So when you're importing a field "alice,bob", it will result in a string property and the content alice,bob (without surrounding quotes - see my very first post). This is the same as $a = "Some,String".
In your script, you were passing this string directly to the ManagedBy argument, and since there is no account 'alice,bob', the command failed.
Note the difference between
Set-DistributionGroup -ManagedBy "alice,bob" (which is the same as the command you created in your initial script)
and
Set-DistributionGroup -ManagedBy "alice","bob" (which is the same as the command you entered manually, except that I added quotes for clarity).

The Split() method on the string 'alice,bob' turns it back into a an array with two separate strings, "alice" and "bob".
1
beardog1113Author Commented:
i am clear now, thank you very much, nice day.
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
Powershell

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.