Bulk edit for Azure groups

%3CLINGO-SUB%20id%3D%22lingo-sub-1207780%22%20slang%3D%22en-US%22%3EBulk%20edit%20for%20Azure%20groups%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1207780%22%20slang%3D%22en-US%22%3E%3CP%3Eimport-CSV%20c%3A%5Ctemp%5Cawsgroups.csv%20%7C%20ForEach%20(Set-DistributionGroup%20-Identity%20%24.DistGroup%20-%20ManagedBy%20%40%7BAdd%3D%22%3COWNER1%3E%22%2C%22%3COWNER2%3E%22%2C%22%3COWNER3%3E%22%3C%2FOWNER3%3E%3C%2FOWNER2%3E%3C%2FOWNER1%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20do%20a%20bulk%20edit%20to%20our%20Azure%20groups%20to%20add%203%20owners%20to%20over%20100%20groups.%20I%20have%20a%20csv%20file%20named%20awsgroups.csv%20in%20my%20temp%20directory%20with%20the%20fields%20DistGroup%2C%20Owner%201%2C%20Owner%202%2C%20and%20Owner%203.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20running%20the%20above%20script%20and%20I%20get%20'The%20operation%20couldnt%20be%20performed%20because%20object%20%24.DistGroup%20couldnt%20be%20found%20on%20Prod.Outlook.com%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsually%2C%20I%20google%20powershell%20commands%20to%20do%20what%20I%20need%20to%2C%20but%20this%20one%20if%20giving%20me%20problems.%20Any%20help%20would%20be%20appreciates%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1207780%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBulk%20Edit%20Azure%20Group%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1207950%22%20slang%3D%22en-US%22%3ERe%3A%20Bulk%20edit%20for%20Azure%20groups%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1207950%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20changing%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%24.DistGroup%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%24_.DistGroup%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EKey%20here%20is%20that%20'%24'%20by%20itself%20isn't%20a%20thing%20isn't%20a%20thing%2C%20but%20'%24_'%20references%20the%20current%20item%20in%20your%20foreach%20loop.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlternatively%20you%20can%20use%26nbsp%3B%3CSPAN%3E%24PSItem%20(e.g.%26nbsp%3B%24PSItem.DistGroup).%20I%20personally%20use%20%24_%20%2C%20but%20there's%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.reddit.com%2Fr%2FPowerShell%2Fcomments%2F5bjgdt%2For_psitem%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ediscussion%20on%20Reddit%3C%2FA%3E%20on%20this%20if%20you're%20interested%20in%20reading%20people's%20thoughts%20on%20it.%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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.