Jump to content

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


Recommended Posts

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)
Link to comment
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...