Bulk edit for Azure groups

Copper Contributor

import-CSV c:\temp\awsgroups.csv | ForEach (Set-DistributionGroup -Identity $.DistGroup - ManagedBy @{Add="<owner1>","<owner2>","<owner3>"

 

I need to do a bulk edit to our Azure groups to add 3 owners to over 100 groups. I have a csv file named awsgroups.csv in my temp directory with the fields DistGroup, Owner 1, Owner 2, and Owner 3.

 

I am running the above script and I get 'The operation couldnt be performed because object $.DistGroup couldnt be found on Prod.Outlook.com"

 

Usually, I google powershell commands to do what I need to, but this one if giving me problems. Any help would be appreciates

1 Reply

Try changing:

 

$.DistGroup

 

To:

 

$_.DistGroup

 

Key here is that '$' by itself isn't a thing isn't a thing, but '$_' references the current item in your foreach loop. 

 

Alternatively you can use $PSItem (e.g. $PSItem.DistGroup). I personally use $_ , but there's a discussion on Reddit on this if you're interested in reading people's thoughts on it.