Add domain users to local admin on remote pc

Comments

7 comments

  • Stephen Valdinger

    When I return from lunch and have a proper environment to code and test I'll fix you right up. This is simple.

    0
    Comment actions Permalink
  • Stephen Valdinger
    $GroupObj = [ADSI]"WinNT://$Computer/Administrators"

    $GroupObj.Add("WinNT://$Domain/$Username")

    Where $computer = the target hostname. If you package this and deploy it to computers setting this to $env:COMPUTERNAME will do the trick.

    $Domain = the domain name you need to use for the user account to add

    $Username = the username you wish to add to the local admin group.

     

    Example usage in a Powershell step:

     

    $GroupObj = [ADSI]"WinNT://$Env:COMPUTERNAME/Administrators"

    $GroupObj.Add("WinNT://CONTOSO/jsmith")
    1
    Comment actions Permalink
  • Tim Moseley

    Worked like a charm. 

    Thank you.

    0
    Comment actions Permalink
  • Stephen Valdinger

    Excellent. Glad to help.

    0
    Comment actions Permalink
  • Kevin Zimmerman

    Steven, I'm trying to modify this script and deploy using PDQDeploy

    I was trying to use the following syntax so that I would not have to update the user name when delpoying it to different workstations, however I can't get it to work. Is it possible to do what I'm requesting?

    $GroupObj = [ADSI]"WinNT://$Env:COMPUTERNAME/Administrators"

    $GroupObj.Add("WinNT://Domain/$Env:%USERNAME%")

    0
    Comment actions Permalink
  • Stephen Valdinger

    You don't need the % around username:

    0
    Comment actions Permalink
  • Dana Simison

    So can we do this? $domain = mydomain.net $userName = jsmith $GroupObj = [ADSI]"WinNT://$Env:COMPUTERNAME/Administrators" $GroupObj.Add("WinNT://$domain/$userName")

    0
    Comment actions Permalink

Please sign in to leave a comment.