Skip to content

Instantly share code, notes, and snippets.

@Oceanswave
Last active March 1, 2018 08:58
Show Gist options
  • Save Oceanswave/876fab9bf87de09b1b9c to your computer and use it in GitHub Desktop.
Save Oceanswave/876fab9bf87de09b1b9c to your computer and use it in GitHub Desktop.
Powershell function to add a user to a local group
function Add-LocalUser{
Param(
$computer=$env:computername,
$group='Guests',
$userdomain=$env:userdomain,
$username=$env:username
)
([ADSI]"WinNT://$computer/$Group,group").psbase.Invoke("Add",([ADSI]"WinNT://$domain/$user").path)
}
#Non-powershell equiv:
#net localgroup administrators mydomain.local\user1 /add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment