Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active December 31, 2015 02:59
Show Gist options
  • Save grenade/7924977 to your computer and use it in GitHub Desktop.
Save grenade/7924977 to your computer and use it in GitHub Desktop.
Add a domain user to a local group
function Add-LocalGroupDomainUser {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $computer,
[Parameter(Mandatory = $true)]
[string] $group,
[Parameter(Mandatory = $true)]
[string] $domain,
[Parameter(Mandatory = $true)]
[string] $user
)
$u = [adsi] "WinNT://$domain/$user"
$g = [adsi] "WinNT://$computer/$group,group"
$g.PSBase.Invoke("Add", $u.Path)
}