Adding User Accounts into a Group

Welcome Forums General PowerShell Q&A Adding User Accounts into a Group

Viewing 3 reply threads
  • Author
    Posts
    • #254033
      Participant
      Topics: 1
      Replies: 1
      Points: 11
      Rank: Member

      What I am trying to achieve is to get a list of users from groupname and then if they are not in groupname2 add them into it, but nothing is happening. Any help would be mush appreciated.

       

      • This topic was modified 4 months, 3 weeks ago by blue_man51.
      • This topic was modified 4 months, 3 weeks ago by blue_man51.
      • This topic was modified 4 months, 3 weeks ago by kvprasoon. Reason: code formatting
      • This topic was modified 4 months, 3 weeks ago by kvprasoon. Reason: correct post
    • #254081
      Participant
      Topics: 25
      Replies: 208
      Points: 792
      Helping Hand
      Rank: Major Contributor

      might be easier to just change your initial groupmember query to include the property memberof. then your check becomes alot simpler, if ($member.memberof -like “*groupname*”) {do something}

      then you don’t have to loop through adprinicpalgroupmembership and evaluate every group, should be faster as well

    • #254087
      Senior Moderator
      Topics: 9
      Replies: 1450
      Points: 5,434
      Helping Hand
      Rank: Community MVP

      You don’t need to use Select-Object here as all the objects are passed through the pipeline, Hence Where-Object has access to all the properties.

      Hope with $getuser -ne $() you are trying to check if its null or not, the right way to do it is $null -ne $getuser

      Try by making above modification to your script.

      • This reply was modified 4 months, 3 weeks ago by kvprasoon. Reason: Post correction
    • #254255
      Participant
      Topics: 1
      Replies: 1
      Points: 11
      Rank: Member

      Thanks all I ended going with

      • This reply was modified 4 months, 3 weeks ago by grokkit. Reason: HTML parsing fix
Viewing 3 reply threads
  • The topic ‘Adding User Accounts into a Group’ is closed to new replies.