How to make list users and user member groups

Welcome Forums General PowerShell Q&A How to make list users and user member groups

Viewing 15 reply threads
  • Author
    Posts
    • #212856
      Participant
      Topics: 1
      Replies: 4
      Points: 23
      Rank: Member

      Hi,

      I’ll try to make script where I get users and groups to which they belong, but group search must have argument “-like groupname*”

       

      Example:

      User, group1,group2

       

      My script:

       

      • This topic was modified 10 months ago by dr_clayss.
      • This topic was modified 10 months ago by dr_clayss.
    • #212868
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      … but group search must have argument “-like groupname*”

      What do you mean with “… must have argument -like groupname”?

      That’s actually all you need:

    • #212877
      Participant
      Topics: 1
      Replies: 4
      Points: 23
      Rank: Member

      … but group search must have argument “-like groupname*”

      What do you mean with “… must have argument -like groupname”?

      I don’t want to list all groups, but only what I need

    • #212907
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      I don’t want to list all groups, but only what I need

      Could you elaborate this a little bit more please?

    • #212949
      Participant
      Topics: 1
      Replies: 4
      Points: 23
      Rank: Member

      Users has member a lot of groups.

      I have groups(examples)

      • dfs_share1_folder1
      • dfs_share1_folder2
      • dfs_share1_folder3
      • dfs_share2_folder1
      • dfs_share2_folder2
      • etc.

      I want to filtered it and find groups for example “name -like “dfs_share1_*” when I don’t need other groups where user is member

    • #212952
      Participant
      Topics: 17
      Replies: 1958
      Points: 4,020
      Helping Hand
      Rank: Community Hero

      Based on Oleg…err @Olaf’s code, try something like this:

    • #212955
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      Hmmm … close …

      if I’m not wrong it should be instead of this

      more like this:

      😛 😉

    • #213192
      Participant
      Topics: 1
      Replies: 4
      Points: 23
      Rank: Member

      Based on Oleg…err @Olaf’s code, try something like this:

      This line doesn’t work

      Empty result.

      • This reply was modified 10 months ago by dr_clayss.
    • #213270
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      Now that you write it in a single line … of course it cannot work. MemberOf is supposed to be an array. Try this:

      BTW: You are allowed to use our suggestions and use it for your own research and play with it to make it run.

      • This reply was modified 9 months, 4 weeks ago by Olaf. Reason: corrected code $user.memberof -> $_.memberof
    • #214617
      Participant
      Topics: 1
      Replies: 4
      Points: 23
      Rank: Member

      It’s doesn’t work.

    • #214620
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      It’s doesn’t work.

      Damn. That happens when you copy code and change it without testing … changed the code above …

      But as I said before: You are allowed to change our suggestions accordingly and debug it when we do something wrong. 😉

    • #214758
      Participant
      Topics: 2
      Replies: 5
      Points: 17
      Rank: Member

      try this

      $groups = "grp1", "grp2","grp3"
      foreach ($group in $groups) {
          Get-ADGroupMember $group | Get-ADUser -Properties samaccountname, userprincipalname |
          Select-Object  samaccountname, userprincipalname,@{n='GroupName';e={$group}}
      }

       

    • #214761
      Participant
      Topics: 2
      Replies: 5
      Points: 17
      Rank: Member

      @rob … how do you insert a block of powershell code ?

    • #214764
      Participant
      Topics: 2
      Replies: 5
      Points: 17
      Rank: Member

      help

      • This reply was modified 9 months, 4 weeks ago by robertrobert59. Reason: testing
    • #214842
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      @rob … how do you insert a block of powershell code ?

      First you could (re-)read the instructions you find in the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!

      When you create a new post you use the “Textview, you insert the code you want, then you select the code and click on the code tag “PRE” – that’s all. 😉

    • #214923
      Participant
      Topics: 2
      Replies: 5
      Points: 17
      Rank: Member

      okk thanks

Viewing 15 reply threads
  • The topic ‘How to make list users and user member groups’ is closed to new replies.