none
Finding multiple groups Object ID RRS feed

  • Question

  • Hello,

    I am using 0365.

    I am trying to retrieve ObjectID of multiple groups in order to use it in  Add-MsolGroupMember later on.

    So I import a csv file that contains DisplayNames of security groups.

    I am trying to have a script that would go through the csv file and for each record of that csv it would find associated group in 0365 that has the same DisplayName and would show me the ObjectID of that group. So in the end, ideally it would export ObjectID of each security group in a new csv.

    I am trying something as below:

    $Groups = Import-csv "C:\Users\Me\SecurityGroupsByDisplayName.csv"
    ForEach ($Group in $Groups) {Get-MsolGroup -all | Where-Object {$_.displayname -eq  $Group.name  | Select ObjectID}}

    Obviously it does not work, although I dont know why it lists all the groups for me, and it does not even select ObjectID only, but shows more information than that.

    Any help, highly appreciated.

    Have a great weekend!




    Friday, May 4, 2018 2:40 PM

Answers

  • Get all groups first then filter the results against the collection o names.

    Get-MsolGroup -all | Where-Object {$_.displayname -in  $allgroupnames}


    \_(ツ)_/

    Friday, May 4, 2018 7:36 PM