Sign in to follow this  
Followers 0
readmedottxt

Removing a local user from a local group (not AD)

3 posts in this topic

I have a workgroup computer. I need to remove a user from the Administrators group.

This always fails, can anyone point me in the right direction?

$varUser = InputBox("user to remove from admins group", "", "")

$objGroup = ObjGet("WinNT://./Administrators")
$objLocalMember = ObjGet("WinNT://./" & $varUser)
$objGroup.Remove($objLocalMember.ADsPath)

Share this post


Link to post
Share on other sites



WMI is a little bit tricky.Try this instead.

$path="net localgroup Administrators Username /Remove"
RunWait(@ComSpec & ' /c ' & $path)

Share this post


Link to post
Share on other sites

Try this:

;coded by UEZ 2011
$srv = "."
$LocalGroup_Name = "Administrators"
$user = "Test"
$objGroup = ObjGet("WinNT://" & $srv & "/" & $LocalGroup_Name & ",group")

If IsObj($objGroup) then
    For $objUser In $objGroup.Members
        If $objUser.Name = $user Then
            $objGroup.Remove($objUser.ADsPath)
            ExitLoop
        EndIf
    Next
EndIf

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0