Lansweeper logo
Home Download Features Demo Buy now Help Support forum
 
    Most requested support articles:
  Lansweeper troubleshooting guide.
  The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
  WMI Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  How to configure the windows firewall using group policies.
  Support:  
 support@lansweeper.com  
Skype: Lansweeper  
  Mo-Fri 9h-17h CET  
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Add local administrator to remote PC
Cobra7
#1 Posted : Monday, August 30, 2010 11:19:34 PM

Rank: Premium user

Groups: Member, Premium Users
Posts: 147
Location: Omaha
This uses Powershell. Save script in your \\server\share directory and name it addadmin.ps1.

This adds the user name to the computer then checks the computer to make sure the user name showed up.

Action is:
Code:
powershell.exe -noexit \\server\share\addadmin.ps1 {computer}


On line 3, change "YourDomain" to what your domain is.

Code:
# Add a domain user to the local Administrators group on the local or a remote computer 

$domainname = "YourDomain"
$erroractionpreference = "SilentlyContinue"

if ($args.count -ge "1") {$computername = $args}
else {$computerName = Read-Host 'Enter computer name or press <Enter> for localhost'}
$userName = Read-Host 'Enter user name'
 
if ($computerName -eq "") {$computerName = "$env:computername"}
([ADSI]"WinNT://$computerName/Administrators,group").Add("WinNT://$domainName/$userName")

$computer = [ADSI]("WinNT://" + $computername + ",computer")
$Group = $computer.psbase.children.find("Administrators")
$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

ForEach($user in $members)

{
if ($user -eq $userName) {$found = $true}
}

if ($found -eq $true) {Write-Host "User $domainName\$userName is now local administrator on $computerName."}
else {Write-Host "User not found"}
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Contact: E-mail Lansweeper - Skype : Lansweeper
Copyright 2004 - 2011 © Hemoco bvba