Command net localgroup Administrateurs $user /DELETE works as a script in MCM but not in Intune, why?

51 Views Asked by At

I'm running a remediation script with this command:

net localgroup Administrateurs $user /DELETE

The script runs fine as a standalone PowerShell script AND as a script executed in MCM (SCCM) but when it runs in Intune it gives me this syntax error:

La syntaxe de cette commande est : NET LOCALGROUP [nom_groupe [/COMMENT:"texte"]] [/DOMAIN] nom_groupe {/ADD [/COMMENT:"texte"] | /DELETE} [/DOMAIN] nom_groupe nom [...] {/ADD | /DELETE} [/DOMAIN]

Not sure how to explain the fact that it bugs on the NET LOCALGROUP command only in Intune and not in MCM...

Ultimately I'm trying to remove some users from the local group Administrators on several machines and that's the only way I found that was compatible with my environment but it seems Intune disagrees.

I tried multiple variations of the line that is bugging like:

net localgroup Administrateurs $user /DELETE
net localgroup Administrateurs "$user" /DELETE
net localgroup Administrateurs '$user' /DELETE

Also, when I use the net localgroup command to only list the members of the Administrateurs group, it works flawlessly in Intune. Only when I try to do the operation with /DELETE does it fail.

Any ideas?

Thanks in advance!

1

There are 1 best solutions below

0
On

As mentioned by Olaf, just use the native Remove-LocalGroupMember command.