Giving/Removing List of Users Access to List of Groups

Welcome Forums General PowerShell Q&A Giving/Removing List of Users Access to List of Groups

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

      Hello all! Good day – forgive me ahead of time for I am a total n00b when it comes to Powershell. Essentially, what I am trying to do is take a list of groups (whether that be imported via CSV or through some sort of Get statement) and add or remove a list of Users via the same methods. Theoretically to me it seems as though it should be simple enough. I am using the Remove-AzureADGroupMember in my example. I’ve tried various methods centered around Foreach but I consistently receive errors such as: “Cannot convert ‘System.Object[]’ to the type ‘System.String'”

      Here is an example of something simple I’d try (each CSV has a column with a name and a column with Object ID):

    • #227524
      Participant
      Topics: 44
      Replies: 97
      Points: 605
      Rank: Major Contributor

      hi
      for removing all groups assigned to a given user I use this
      my csv file contains 2 colums one with samaccountName and the other with email.

       

      • This reply was modified 6 months, 3 weeks ago by acer460527.
    • #227551
      Participant
      Topics: 17
      Replies: 1872
      Points: 3,640
      Helping Hand
      Rank: Community Hero

      Here is the issues with your code:

      The error is you are providing an object, not a string. This is due to an implicit loop when you do object.property

      Here is corrected code so you can compare to the original:

    • #227581
      Participant
      Topics: 1
      Replies: 1
      Points: 13
      Rank: Member

      Thank you both so much – two very helpful and unique responses! Acer I hadn’t even thought of using get-AzureAdUserMembership so that’s a really cool method. And Rob, your reply was exactly what I was looking for – someone to critique what I had done. It was nice to see that I was not too far off from what actually needed to be done!

Viewing 3 reply threads
  • The topic ‘Giving/Removing List of Users Access to List of Groups’ is closed to new replies.