exclude quotation mark while powershell a CSV file

hello experts
my example CSV file is below

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.....


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

thank you
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
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
PS C:\Temp>

Open in new window

Are You Protected from Q3's Internet Threats?

Every quarter, WatchGuard's Threat Lab releases a security report that analyzes the top threat trends impacting companies around the world. For Q3, we saw that 6.8% of the top 100K websites use insecure SSL protocols. Read the full report to start protecting your business today!

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
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

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
beardog1113Author Commented:
that s great, thank you
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)
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".
beardog1113Author Commented:
i am clear now, thank you very much, nice day.
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

From novice to tech pro — start learning today.