Using PowerShell to export Active Directory Group Members to a CVS File | Pipe2Text.com<\/a> ) : \nGet-ADGroupMember -Identity “groupname” | select samname | Export-csv -path “…\n <\/blockquote>\n<\/aside>\n","upvoteCount":1,"datePublished":"2017-08-09T16:27:47.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/2","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi Spiceheads,<\/p>\n
I’m a novice PS user and I have something I’d like to do via a script but I’m not sure how to get it done.<\/p>\n
I have a list of ~150 names (formatted Last, First MI) in excel. Some have middle initials and others do not. I need to add all of these users to a DL.<\/p>\n
I know I need a script to take names in the format I have and return a list of SAM account names, and then I need a script to take each SAM account name and add it to the DL I specify.<\/p>\n
I’ve never really worked with powershell and csv’s before so any advice is very welcome!<\/p>\n
Thanks!<\/p>","upvoteCount":5,"datePublished":"2017-08-09T16:21:26.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/1","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"
Thanks a lot!<\/p>\n
I did not intend to come off like I wanted people to write things for me <\/p>\n
It looks like these threads will be very useful! Thanks again!<\/p>","upvoteCount":1,"datePublished":"2017-08-09T16:48:52.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/3","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"
So I’ve made some progress but I’m having issues getting the -filter syntax down. I’m using code copied from an example script that has worked for others but I get \"Get-ADUser : the search filter cannot be recognized.<\/p>\n
Here’s what I’m using. Any ideas?<\/p>\n
$User = Get-ADUser -Filter \"Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'\" -Properties EmailAddress\n<\/code><\/pre>\nThanks!<\/p>","upvoteCount":0,"datePublished":"2017-08-10T09:30:44.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/4","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Roy DeSimone:<\/div>\n
\nSo I’ve made some progress but I’m having issues getting the -filter syntax down. I’m using code copied from an example script that has worked for others but I get \"Get-ADUser : the search filter cannot be recognized.<\/p>\n
Here’s what I’m using. Any ideas?<\/p>\n
$User = Get-ADUser -Filter \"Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'\" -Properties EmailAddress\n<\/code><\/pre>\nThanks!<\/p>\n<\/blockquote>\n<\/aside>\n
Replying to myself here for sake of getting my solution out on the thread - my issue was with the formatting of my .csv. initially I had column A containing LastName, FirstName Initial.<\/p>\n
I split that out so that column A was last names, column B was first names, etc. and it did the trick!<\/p>\n
thanks for your assistance JitenSh! now comes the part where I get the info into the new DL.<\/p>","upvoteCount":1,"datePublished":"2017-08-10T10:18:27.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/5","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"
Thanks again for the assistance over here. I’ve created and populated my DL and things are good!<\/p>\n
One last question on the topic.<\/p>\n
Using the filter for first name and last name - how could I update the code to handle multiple hits? For instance:<\/p>\n
If there are multiple users with the same name, such as John A. Smith, with SAM accounts of JASmith, JASmith1 and JASmith2 - is there a way to get the script to prompt for user selection in a situation like that? Can I get it to provide a list of names that match the filter along side other data from the account so I can make a selection?<\/p>\n
for example:<\/p>\n
1. JASmith Chicago CEO\n2. JASmith1 Los Angeles Analyst\n3. JASmith2 Miami Section Chief\n\nMake a selection to continue: \n\n<\/code><\/pre>\nthanks!<\/p>","upvoteCount":0,"datePublished":"2017-08-10T11:19:36.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/6","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"
on the link gungnirs script will tell you if account is missing, I am glad you are able to figure out, Best mentor and tutor is yourself<\/p>","upvoteCount":1,"datePublished":"2017-08-10T11:48:17.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/7","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"\n\n
<\/div>\n
JitenSh:<\/div>\n
\non the link gungnirs script will tell you if account is missing, I am glad you are able to figure out, Best mentor and tutor is yourself<\/p>\n<\/blockquote>\n<\/aside>\n
Yep, I saw that and it works well but I’m also concerned with getting multiple hits, as opposed to a miss.<\/p>","upvoteCount":0,"datePublished":"2017-08-10T11:49:53.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/8","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"
because it uses wild card in first name and last name suppose there is user name Jon snow and jon cena it may reflect both accounts<\/p>\n
I prefer this way<\/p>\n
#csv\nuser\nJon snow\nned stark\n\n$list = ipcsv C:\\powershell\\Test.csv\nForEach($user in $list){ \n$dn = $user.user\nGet-ADUser -Filter { displayName -like $dn } -Properties EmailAddress | select Givenname,Surname,Samaccountname,EmailAddress |Export-Csv C:\\temp\\export1.csv -NoType -Append } \n\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2017-08-10T12:41:41.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/9","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Roy DeSimone:<\/div>\n
\nUsing the filter for first name and last name - how could I update the code to handle multiple hits? For instance:<\/p>\n
If there are multiple users with the same name, such as John A. Smith, with SAM accounts of JASmith, JASmith1 and JASmith2 - is there a way to get the script to prompt for user selection in a situation like that? Can I get it to provide a list of names that match the filter along side other data from the account so I can make a selection?<\/p>\n
for example:<\/p>\n
1. JASmith Chicago CEO\n2. JASmith1 Los Angeles Analyst\n3. JASmith2 Miami Section Chief\n\nMake a selection to continue: \n\n<\/code><\/pre>\nthanks!<\/p>\n<\/blockquote>\n<\/aside>\n
You can use Out-GridView to do this.<\/p>\n
$ADUser = Get-ADUser -Filter \"Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'\"\n\n$User = if( @($ADUser).Count -gt 1 ){\n $ADUser |\n Out-GridView -OutputMode Multiple\n }\nelse{\n $ADUser\n }\n\n$User\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2017-08-11T16:48:20.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/10","author":{"@type":"Person","name":"gungnir","url":"https://community.spiceworks.com/u/gungnir"}},{"@type":"Answer","text":"That out-gridview is pretty awesome!<\/p>\n
How can I specify which columns I want from the aduser in the gridview?<\/p>\n
Can I get it to put the location attribute from AD in a column? can I get it to not print the GUID and SID info?<\/p>\n
thanks a million!<\/p>\n
@gungnir<\/a><\/p>","upvoteCount":0,"datePublished":"2017-08-15T14:54:18.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/11","author":{"@type":"Person","name":"roydesimone4630","url":"https://community.spiceworks.com/u/roydesimone4630"}},{"@type":"Answer","text":"\nHow can I specify which columns I want from the aduser in the gridview?<\/p>\n
Can I get it to put the location attribute from AD in a column? can I get it to not print the GUID and SID info?<\/p>\n
thanks a million!<\/p>\n<\/blockquote>\n
Mostly by using a Select-Object :<\/p>\n
$ADUser |\n Select-Object choose, property, names, here |\n Out-GridView -OutputMode Multiple\n<\/code><\/pre>\nYou may also need to request additional properties from the Get-ADUser cmdlet. Using the -Properties parameter.<\/p>","upvoteCount":1,"datePublished":"2017-08-15T15:20:39.000Z","url":"https://community.spiceworks.com/t/scripting-group-membership-additions-from-a-csv-file/598862/12","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}}]}}
Hi Spiceheads,
I’m a novice PS user and I have something I’d like to do via a script but I’m not sure how to get it done.
I have a list of ~150 names (formatted Last, First MI) in excel. Some have middle initials and others do not. I need to add all of these users to a DL.
I know I need a script to take names in the format I have and return a list of SAM account names, and then I need a script to take each SAM account name and add it to the DL I specify.
I’ve never really worked with powershell and csv’s before so any advice is very welcome!
Thanks!
5 Spice ups
jitensh
(JitenSh)
August 9, 2017, 4:27pm
2
We do not write sripts but helps you when you are stucked
check this topic
All,
I'm needing some help with my foreach script. My current need is identifying SamAccount & EmailAddress based on AD user's first & last name. My script works for that information but my foreach will not always find a samaccount & email based on first & last name. For those null objects how do I output "Missing" or a string for each of those not found objects? I'm assuming this will be an if statement inside the foreach. I'm wanting to keep my rows aligned in my csv output. This will not on…
and this
Trying to keep this simple but basically I received a request to create a sec group. A large number for the 200 people in that group are already in another group which I wanted to use to start the group and I can do the rest manually as its only a handful.
I have exported all the user samaccountnames to a .csv file (Thank you Using PowerShell to export Active Directory Group Members to a CVS File | Pipe2Text.com ) :
Get-ADGroupMember -Identity “groupname” | select samname | Export-csv -path “…
1 Spice up
Thanks a lot!
I did not intend to come off like I wanted people to write things for me
It looks like these threads will be very useful! Thanks again!
1 Spice up
So I’ve made some progress but I’m having issues getting the -filter syntax down. I’m using code copied from an example script that has worked for others but I get "Get-ADUser : the search filter cannot be recognized.
Here’s what I’m using. Any ideas?
$User = Get-ADUser -Filter "Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'" -Properties EmailAddress
Thanks!
Roy DeSimone:
So I’ve made some progress but I’m having issues getting the -filter syntax down. I’m using code copied from an example script that has worked for others but I get "Get-ADUser : the search filter cannot be recognized.
Here’s what I’m using. Any ideas?
$User = Get-ADUser -Filter "Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'" -Properties EmailAddress
Thanks!
Replying to myself here for sake of getting my solution out on the thread - my issue was with the formatting of my .csv. initially I had column A containing LastName, FirstName Initial.
I split that out so that column A was last names, column B was first names, etc. and it did the trick!
thanks for your assistance JitenSh! now comes the part where I get the info into the new DL.
1 Spice up
Thanks again for the assistance over here. I’ve created and populated my DL and things are good!
One last question on the topic.
Using the filter for first name and last name - how could I update the code to handle multiple hits? For instance:
If there are multiple users with the same name, such as John A. Smith, with SAM accounts of JASmith, JASmith1 and JASmith2 - is there a way to get the script to prompt for user selection in a situation like that? Can I get it to provide a list of names that match the filter along side other data from the account so I can make a selection?
for example:
1. JASmith Chicago CEO
2. JASmith1 Los Angeles Analyst
3. JASmith2 Miami Section Chief
Make a selection to continue:
thanks!
jitensh
(JitenSh)
August 10, 2017, 11:48am
7
on the link gungnirs script will tell you if account is missing, I am glad you are able to figure out, Best mentor and tutor is yourself
1 Spice up
Yep, I saw that and it works well but I’m also concerned with getting multiple hits, as opposed to a miss.
jitensh
(JitenSh)
August 10, 2017, 12:41pm
9
because it uses wild card in first name and last name suppose there is user name Jon snow and jon cena it may reflect both accounts
I prefer this way
#csv
user
Jon snow
ned stark
$list = ipcsv C:\powershell\Test.csv
ForEach($user in $list){
$dn = $user.user
Get-ADUser -Filter { displayName -like $dn } -Properties EmailAddress | select Givenname,Surname,Samaccountname,EmailAddress |Export-Csv C:\temp\export1.csv -NoType -Append }
1 Spice up
gungnir
(Gungnir)
August 11, 2017, 4:48pm
10
Roy DeSimone:
Using the filter for first name and last name - how could I update the code to handle multiple hits? For instance:
If there are multiple users with the same name, such as John A. Smith, with SAM accounts of JASmith, JASmith1 and JASmith2 - is there a way to get the script to prompt for user selection in a situation like that? Can I get it to provide a list of names that match the filter along side other data from the account so I can make a selection?
for example:
1. JASmith Chicago CEO
2. JASmith1 Los Angeles Analyst
3. JASmith2 Miami Section Chief
Make a selection to continue:
thanks!
You can use Out-GridView to do this.
$ADUser = Get-ADUser -Filter "Givenname -like '*$FirstFilter*' -and Surname -like '*$SecondFilter*'"
$User = if( @($ADUser).Count -gt 1 ){
$ADUser |
Out-GridView -OutputMode Multiple
}
else{
$ADUser
}
$User
1 Spice up
That out-gridview is pretty awesome!
How can I specify which columns I want from the aduser in the gridview?
Can I get it to put the location attribute from AD in a column? can I get it to not print the GUID and SID info?
thanks a million!
@gungnir
psophos
(M Boyle)
August 15, 2017, 3:20pm
12
How can I specify which columns I want from the aduser in the gridview?
Can I get it to put the location attribute from AD in a column? can I get it to not print the GUID and SID info?
thanks a million!
Mostly by using a Select-Object :
$ADUser |
Select-Object choose, property, names, here |
Out-GridView -OutputMode Multiple
You may also need to request additional properties from the Get-ADUser cmdlet. Using the -Properties parameter.
1 Spice up