I have a script I'm using to auto add domain users into a specific group. It also incorporates a stop/restart of a 3rd party service that adds them into a secure user file. I'd like for this script to end the moment it finds that the user is already a part of the group, and NOT stop/start the service. This is what I have so far:
When I run the script, I get the below message, which is normal, and then the script continues to run, thus restarting the service anyway.
Thanks for all your help in advance! asked Sep 27, 2021 at 18:05
1 You could check the output of
answered Sep 27, 2021 at 18:36
Cpt.WhaleCpt.Whale 3,8941 gold badge11 silver badges14 bronze badges 2 Thanks to @Cpt.Whale for helping me on this. I was running into the PowerShell "Get-LocalGroupMember - Failed to compare two elements in the array." bug as described here when you have orphaned SIDs. I came across this post here that helped me figure out how to remove the orphaned SIDs. Below is the new fully working script. Important Note: You need PowerShell V5.1 for this. Also, you have to enable remote signing. From Powershell check first with a simple "Set-ExecutionPolicy RemoteSigned" (may as well run "winrm quickconfig", as well). Working Script:
answered Oct 24, 2021 at 17:25
local-groupssecurity-groupswindows 10 Following commands run on a Windows 10 VM that's joined to AzureAD:
Any idea why the PowerShell Get-LocalGroupMember command is generating an error on the Administrators group whereas net localgroup works as does Get-LocalGroupMember for the Users group? |