-
-
Save aldrichtr/af3d1f696676d50edc30c2f1c17695b9 to your computer and use it in GitHub Desktop.
Powershell ADSI tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment