r/PowerShell • u/Mskews • May 27 '26
Solved I thought there would be an easier way without have to use %?
$azureUsers.id | %{New-MgGroupMember -GroupId $group.Id -DirectoryObjectId $_ }
Thought the point of piping was no need for foreach? My powershell is getting worse over time!
0
Upvotes
3
u/WhAtEvErYoUmEaN101 May 27 '26
I have no idea what you are rambling about, but to answer your question:
A pipe moves data from one end to another, but if the downstream command can’t handle >1 input objects you have to resort to foreach
1
u/Adam_Kearn May 27 '26
As others have mentioned that command doesn’t support an array to import in bulk.
You could use this but this has a bulk limit of 20…which still isn’t ideal and means adding logic and other loops.
The best solution is just to for the ForEach command and keep calling the “add group member” function. Even with a few thousand users it will only take a few seconds.
1
u/node77 May 29 '26
I am really not sure why people assume AI all the time. I do it in reverse meaning answer the question then see AI. It’s almost always the same. I guess you could notice the sentences a little tighter? Any I am off topic. Sorry.
0
u/BlackV May 27 '26 edited May 27 '26
I don't see it mentioned but you can add multiple user to a group in 1 go using graph cmdlets
You don't need the for each at all
On mobile so no example code handy, odata and batches will do that
Edit: sorry, Adam Kearn mentioned it
-2
u/jeffrey_f May 27 '26
The idea of a Yubikey is they should never travel in the same container. If they steal the laptop and case with the key inside, they have full access. The better option is MFA through their phone. If they steal the laptop, the second part of the authentication is detached and in your pocket
I hate MFA, but it is a necessary evil.
0
u/[deleted] May 27 '26
[deleted] — view deleted comment
0
u/[deleted] May 27 '26
[deleted] — view deleted comment