AzureADuser foreach question

Welcome Forums General PowerShell Q&A AzureADuser foreach question

Viewing 2 reply threads
  • Author
    Posts
    • #281716
      Participant
      Topics: 46
      Replies: 98
      Points: 633
      Rank: Major Contributor

      Hi All

      the goal of this to retrieve the objectID from a disabled user and to remove this user from all the azureAD groups.
      In order to do this I need to get the object from the user first

      when using this as a standalone command

      it works like a charm
      however when I want to use it in a foreach I get the below mentioned error

      and the error is this
      get-azureAdUser : Error occurred while executing GetUsers
      Code: Request_UnsupportedQuery
      Message: Unsupported or invalid query filter clause specified for property ‘userPrincipalName’ of resource ‘User’.
      any Idea on how to get this sorted out?

    • #281752
      Participant
      Topics: 9
      Replies: 706
      Points: 2,837
      Helping Hand
      Rank: Community Hero

      Only a base variable can be expanded in a string. Since you need to reference the samaccountname property surround it with a subexpression. So change

      “$user.samaccountname”

      to

      ”$($user.samaccountname)”

    • #281791
      Participant
      Topics: 46
      Replies: 98
      Points: 633
      Rank: Major Contributor

      THanks Doug,
      an additional question that pops in my mind. A user can be member in multiple groups and this will as such also be multiple times populated in my export is there a way that I Can use distinct to just use a given user.objectid once? in the following code

      thanks again for your help

Viewing 2 reply threads
  • You must be logged in to reply to this topic.