'Is there a powershell wildcard for users?
I need a script to remove local admin users that get created when they set up their devices. I use the command net localgroup administrators AzureAD\NameOfUser /delete.
How can I have a wildcard in place of "NameOfUser"? There is only one user in that group that starts with AzureAD\ so a wild card for any amount of characters would work for me. I tried AzureAD\* that doesn't seem to be accepted.
Solution 1:[1]
As stated in comments you can probably use
(net localgroup administrators) -like 'AzureAD\*' | ForEach-Object { net localgroup administrators $_ /DELETE }
Essentially you are taking the response of net localgroup administrators, filtering for only lines that start with "AzureAD" using -like and then running net local group administrators <object_name> /DELETE for each matching object
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel |
