skip to Main Content

I’m have some groups on azure, which I’m retriving with Get-AzADGroup like so:

Get-AzADGroup -Filter "startsWith(DisplayName, ‘groupname’)"

which yields the displayname, the id, the mailnickname and the discription..

What I want to do is to get the ID only and put it into a variable. How do I do this?

2

Answers


  1. To return only specific properties, you can pipe the results into Select-Object and specify which properties

    $variable = Get-AzADGroup -Filter "startsWith(DisplayName, 'groupname')" | Select-Object Id
    

    Alternatively, you can store the entire results in the variable, and use dot-notation to get a specific property

    $variable = Get-AzADGroup -Filter "startsWith(DisplayName, 'groupname')"
    
    $variable.Id
    
    Login or Signup to reply.
  2. 😆 I spent all day in Graph doing this very thing.
    Eight hours and four lines of code. I love my work.

    If it were me, I would try,

    (Get-AzADGroup -Filter "startsWith(DisplayName, 'groupname')").ID

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search