Script Examples

Scenario: Review the current membership of the local admin group. Then if the current user is a member add their stub account in the target-migration domain Contoso (for AD migration) to the local admin group.

$mydomain = $env:userdomain
$migdomain = “CONTOSO”
$user = [Environment]::UserName
$computer = $env:computername
$group = “Administrators”
$admins = net localgroup administrators
$d = $admins.Contains(“$mydomain\$user”)
If ($d -eq “True”)
{
$de = [ADSI]“WinNT://$computer/$group,group”
$de.psbase.Invoke(“Add”,([ADSI]“WinNT://$migdomain/$user”).path)
}
Else {
exit}