Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell ADSI tricks
# Add a domain user to a remote server local group, if your current user has admin over the remote machine
powershell -c ([ADSI]'WinNT://SERVER/Administrators,group').add('WinNT://DOMAIN/USER,user')
# Get all local groups on a remote server
powershell -c "([ADSI]'WinNT://SERVER,computer').psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach { ($_.name)[0]}"
# Find members of the local Administrators group on a remote server
powershell -c "$([ADSI]'WinNT://SERVER/Administrators,group').psbase.Invoke('Members') | foreach { $_.GetType().InvokeMember('ADspath', 'GetProperty', $null, $_, $null).Replace('WinNT://', '') }"
# Enable the local Administrator account on a remote server
powershell -c "$a=([ADSI]'WinNT://SERVER/Administrator,user');$a.UserFlags=2;$a.CommitChanges()"
# Disable the local Administrator account on a remote server
powershell -c "$a=([ADSI]'WinNT://SERVER/Administrator,user');$a.UserFlags=512;$a.CommitChanges()"
@potatoqualitee

This comment has been minimized.

Show comment
Hide comment
@potatoqualitee

potatoqualitee May 8, 2016

HEY THANKS HARMJ0Y, I needed this and stumbled upon you ;)

HEY THANKS HARMJ0Y, I needed this and stumbled upon you ;)

@AFineDayFor

This comment has been minimized.

Show comment
Hide comment
@AFineDayFor

AFineDayFor Nov 28, 2016

I also needed to stumble upon this, thanks :)

I also needed to stumble upon this, thanks :)

@jedilibrarian

This comment has been minimized.

Show comment
Hide comment
@jedilibrarian

jedilibrarian Mar 31, 2017

Found out how to do some of these earlier today but not all. Useful stuff thank you for sharing.

Found out how to do some of these earlier today but not all. Useful stuff thank you for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment