none
Getting AD Group members from Import-CSV RRS feed

  • Question

  • I have a list of 1000 or so AD groups that I need to get their members' givenName and sn and export them. I am not familiar with Get-ADGroupMember cmdlet.  

    Kind of rushing... please help

    Monday, June 1, 2015 4:10 PM

Answers

  • Do you mean something like this?


    import-csv "list.csv" | foreach-object {
      $groupName = $_.Group
      get-adgroupmember $groupName | foreach-object {
        $user = get-aduser $_
        new-object PSObject -property @{
          "Group" = $groupName
          "Member UserName" = $user.SamAccountName
          "Member GivenName" = $user.GivenName
          "Member Surname" = $user.surName
        }
      }
    }


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by jrv Monday, June 1, 2015 9:49 PM
    • Marked as answer by Bill_StewartModerator Monday, July 13, 2015 3:26 PM
    Monday, June 1, 2015 9:41 PM
    Moderator

All replies

  • If you're not familiar with a cmdlet, look up the documentation and read the examples.

    https://technet.microsoft.com/en-us/library/ee617193.aspx

    There is really no need to be helpless when search engines are available.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 1, 2015 4:17 PM
    Moderator
  • I have no problems when running the cmdlet on a single group. But I have over 1000 so I need to import a csv. This is where I am running into issues. I have spent the last few hours searching for examples or documentation and I am unable to find a single example close to what I need.
    Monday, June 1, 2015 4:19 PM
  • The problem is that you have not posted an example of what your CSV file looks like (we don't even know if it is really a CSV file or just some kind of text file that you're incorrectly calling a CSV file), the command you are using that isn't working, and how it isn't working (error messages), etc.

    Remember: We don't have access to your system, and we can't see your screen.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 1, 2015 4:26 PM
    Moderator
  • I know what a comma separated value file is sir... I don't understand why the people on this blog are so rude and unwilling to help. I will try powershell.com

    Monday, June 1, 2015 4:29 PM
  • That's fine, but we actually are not able to help if you don't give any good information.

    I point out the CSV question because I have seen many people using Import-Csv on a plain-text file all the while calling it (incorrectly) as CSV file. This is a common cause of errors.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 1, 2015 4:49 PM
    Moderator
  • I have some experience with different programming languages... when running into a problem, I research on my own before coming to a blog. This isn't me trying to be lazy... I am at a dead end. As far as seeing "my screen" as you put it... that doesn't prevent experts from giving a quick example of code... at least not on any other blog site that I've ever reached out for help. 
    Just disappointed that the top place to get powershell help really isnt help... just a bunch of arrogant "know it alls" that like to demean people who want to learn and say "read this" or "read that"... hello... I HAVE but need help... that IS what a blog is for!
    Monday, June 1, 2015 5:05 PM
  • So to get help, you're going to need a post at least a minimal example - http://sscce.org/

    We can often spot common mistakes very quickly when we can see the actual data (example data from CSV file) and the PowerShell command(s) you're trying to run.

    Without a short, self-contained example of your problem, we can't help.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 1, 2015 5:33 PM
    Moderator
  • The help for Import-Csv will answer your question.

    Import-Csv | %{Get-AdGroupMember $_.Name}

    You certainly didn't search very hard as there are thousands of examples.

    I searched for "import csv get adgroupmember".  The very frist itemlisted answers your question in great detail.

    https://www.google.com/?gws_rd=ssl#newwindow=1&q=import+csv+get+adgroupmember

    Stop accusing others of being rude when all you want to do is badger someone else into doing your work for you.

    In the last few weeks I have had numerous posters claim to have programming experience and swear they knew what a CSV file was.  In all cases they had a bad CSV for any one of a number of reasons.  Most had not read the help and the solution to their problems were nearly always given in the help files.

    No one can answer a vague question like you asked.  The only way to help is to ask for better and less ambiguous information.


    \_(ツ)_/

    Monday, June 1, 2015 5:34 PM
  • Believe it or not... that little bit helped me. I am the type of person that needs to see examples to know what its doing. I have read and read and most of the time... doesnt make a lot of sense until I see an example. Thanks jrv. I do have one little problem that I hope someone can help with.

    this is what I have so far

    $Groups = Import-Csv c:\Temp\Groups.csv
    
    $Groups | % { Get-ADGroupMember -Identity $_.group} | Get-ADUser -Properties givenName, sn | select givenName, sn | Out-GridView

    The issue that I am having now is that its simply giving me all the members of the groups but not separating what users are with what group :(

    Monday, June 1, 2015 9:19 PM
  • Every help topic has examples. hut you, like many others, are just to lazy to read them.  Try reading the examples in the future.  WHat I posted was one of the examples.


    \_(ツ)_/

    Monday, June 1, 2015 9:40 PM
  • Do you mean something like this?


    import-csv "list.csv" | foreach-object {
      $groupName = $_.Group
      get-adgroupmember $groupName | foreach-object {
        $user = get-aduser $_
        new-object PSObject -property @{
          "Group" = $groupName
          "Member UserName" = $user.SamAccountName
          "Member GivenName" = $user.GivenName
          "Member Surname" = $user.surName
        }
      }
    }


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by jrv Monday, June 1, 2015 9:49 PM
    • Marked as answer by Bill_StewartModerator Monday, July 13, 2015 3:26 PM
    Monday, June 1, 2015 9:41 PM
    Moderator
  • Every help topic has examples. hut you, like many others, are just to lazy to read them.  Try reading the examples in the future.  WHat I posted was one of the examples.


    \_(ツ)_/

    too lazy? that's what I was talking about earlier about peoples attitudes on here. Wasn't even talking to you but merely responded to another person being rude to me and you act like it somehow involved you. not to mention that I already told you that I do plenty of reading. yes, there are 100s examples... you are right which is exactly why I need someone who is an expert (clearly I am not) explain which example is close to what I need. I tried hundreds of examples and tweaking of them all failed BEFORE I came on here to ask for help.
    Monday, June 1, 2015 11:47 PM
  • Do you mean something like this?


    import-csv "list.csv" | foreach-object {
      $groupName = $_.Group
      get-adgroupmember $groupName | foreach-object {
        $user = get-aduser $_
        new-object PSObject -property @{
          "Group" = $groupName
          "Member UserName" = $user.SamAccountName
          "Member GivenName" = $user.GivenName
          "Member Surname" = $user.surName
        }
      }
    }


    -- Bill Stewart [Bill_Stewart]

     that is beautiful! mind me asking... what does the $_ mean?
    Monday, June 1, 2015 11:48 PM
  • Again you are missing the point. You marked you answer to a response as the answer. It is not.

    No one is being rude.  You are just not understanding that we cannot help if your questions are vague and incomplete.

    You need to spend a little bit more time trying to understand why there are issues.

    You say you do plenty of reading but you sseem too not understand the content of what you read.  Try starting by learning how to use help.  Most untrainedpeople just tpy e "help <command""  that will not get you all of the help.LEarn help as a starter by typing "help help" and reading all of it very carefully.

    The help system is extensive and you are missing most of it.


    \_(ツ)_/

    Monday, June 1, 2015 11:59 PM
  • I hope like hell you aren't an educator. I admittedly say over and over that I need direction and instead of trying to help... you belittle people to make yourself feel superior. I hope you feel good about yourself
    Tuesday, June 2, 2015 1:35 AM
  • I hope like hell you aren't an educator. I admittedly say over and over that I need direction and instead of trying to help... you belittle people to make yourself feel superior. I hope you feel good about yourself

    What!  Are  you wimping out?  Is the program too difficult?

    You need to learn how to learn.  Your excuses will not help you.  If you cannot learn how to learn thenyou will be forever doomed to trivial gripes.

    Join the party.  Learn how to read. Be literate.  You too can be a tech an d not just another noisy user.

    I know.  This stuff is hard.  Forgive me if I demand too much of you.  I believe you can do it.  You only need to have faith in yourself.

    Are you up to the challenge?


    \_(ツ)_/

    Tuesday, June 2, 2015 1:58 AM
  • that is beautiful! mind me asking... what does the $_ mean?

    You can get the answer by reading the PowerShell help.


    PS C:\> help ForEach-Object
    

    You will ultimately save time in the long run if you learn PowerShell. The $_ variable is a basic concept.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 2, 2015 3:11 PM
    Moderator
  • I hope like hell you aren't an educator. I admittedly say over and over that I need direction and instead of trying to help... you belittle people to make yourself feel superior. I hope you feel good about yourself

    What!  Are  you wimping out?  Is the program too difficult?

    You need to learn how to learn.  Your excuses will not help you.  If you cannot learn how to learn thenyou will be forever doomed to trivial gripes.

    Join the party.  Learn how to read. Be literate.  You too can be a tech an d not just another noisy user.

    I know.  This stuff is hard.  Forgive me if I demand too much of you.  I believe you can do it.  You only need to have faith in yourself.

    Are you up to the challenge?


    \_(ツ)_/

    Again, condescending (proving my point)... I am trying to learn but can't find knowledgeable resources that know how to teach.  
    Wednesday, June 3, 2015 3:15 PM
  • Again, condescending (proving my point)... I am trying to learn but can't find knowledgeable resources that know how to teach.  

    You continuously miss my point. You need to start by carefully reading the help. I get crazy and try to shake you up so you will hear the same piece of advice that others have also tried to tell you.

    If you take the time to read the help you will find most of your answers.  The resources that you seek are right in front of you.  You say you need direction but seem to ignore all suggestions.  I know PowerShell is confusing to people who are not formally trained in computer engineering or software engineering.  It can still be learned but requires a considerable amount of research until you get comfortable with the basics.

    Once you get the basics most of your confusion will magically disappear.  Believe  me. We have all seen this many times.


    \_(ツ)_/

    Wednesday, June 3, 2015 3:44 PM