Change Variable to add quotes

I have a script to pull data from a CSV file with about 1000 lines. One of the fields is for the owner/s of a group. I found that I need to surround each user from a field/variable in quotes then comma separate them, but i'm not sure how to go about this within my script

This is what the current variable will look like when pulled from the CSV.

variable = user1@domain.com,user2@domain.com,user3@domain.com

(it's a first.last for each user)

What i need it to look like is 

variable = "user1@domain.com","user2@domain.com","user3@domain.com"

I'm not sure what the best route would be to get all the users surrounded with quotes. I can use -split to separate them by line but then need to rejoin them with the quotes.

The command is for set-distributiongroup

Thanks

May 31st, 2015 3:14pm

Yoouor question is very vague.  Those fields in a CSV file do not require quotes to import.  I suspect you are misunderstanding the issue in some way.  Post an example of your current CSV file and the error you are getting when you load it.  We will show you why you are getting errors.

Example that works with not issues:

CSV File contents:

email1,email2,email3
user1@domain.com,user2@domain.com,user3@domain.com
user1@domain.com,user2@domain.com,user3@domain.com
user1@domain.com,user2@domain.com,user3@domain.com

This is how to load it. 

Import-Csv file.csv

This is what it will look like:

PS C:\temp2> import-csv file.csv

email1           email2           email3
------           ------           ------
user1@domain.com user2@domain.com user3@domain.com
user1@domain.com user2@domain.com user3@domain.com
user1@domain.com user2@domain.com user3@domain.com




Try it to see that it works.

Free Windows Admin Tool Kit Click here and download it now
May 31st, 2015 3:31pm

Sorry, I didn't think I was vague yet it's always very clear in my own mind. :)

The basics is all i want to do is change:

user@here,user2@here,user3@here

To

"user@here","user2@here","user3@here"

Change a variable. Don't worry about anything else. just let me know how to do that from within a powershell script. I'm still 'hacking' away at Powershell so i'm far from an expert.

Thanks again

May 31st, 2015 5:57pm

No idea what you mean by change a variable.    What is in the CSV file? Post a sample.
Free Windows Admin Tool Kit Click here and download it now
May 31st, 2015 6:04pm

If you are trying to awsk how to put qupates inside of a variable then this is how:

$myvar='"user@here","user2@here","user3@here"'

The variable will now have the quotes in it.  Just disply the variable to see them:

Just type $myvar

May 31st, 2015 6:07pm

The basics is all i want to do is change:

user@here,user2@here,user3@here

To

"user@here","user2@here","user3@here"

I'm not exactly clear on what you're after either, but here's something you can play with:

$variable = 'user1@domain.com,user2@domain.com,user3@domain.com'

$variable = ($variable.Split(',') | % { "`"$_`"" }) -join ','

$variable

Free Windows Admin Tool Kit Click here and download it now
May 31st, 2015 8:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics