To make a long story short, I run a script on my local pc that executes on a remote PC. This script creates a local account on the remote pc and then adds it to the admin group. Then the remote pc reboots, auto logs in with the new local account (which should have admin rights) and executes a .bat file that was placed in the startup folder.
Lately, I've been noticing the file will fail to execute (the .bat cmd window will just repeatedly open and close rapidly) and when I check the administrators group, I see the local account isn't a member. This doesn't happen every time but it happens enough to be a problem. This process used to work 100% of the time so what's up? Is it being removed from admin sometimes?
(There is a lot more to the script but I just included the relevant part)
Invoke-Command -ComputerName PC -ScriptBlock {
$NewPass = ConvertTo-SecureString -String "ExamplePass" -AsPlainText -Force
New-LocalUser -Name "ExampleUser" -AccountNeverExpires -Password $NewPass -PasswordNeverExpires
Add-LocalGroupMember -Member "ExampleUser" -Group "Administrators"
Restart-Computer
}