简体   繁体   中英

How can I turn a local user into an administrator via the PowerShell command line?

PowerShell newcomer here, I'm writing a script which prepares newly installed PC's to be merged with my IT firms network. One task I'm having trouble with turning a local user account that I have created via PowerShell into a local administrator.

It is crucial that I use PowerShell to do this, but I haven't yet come across anything in my research. Also any help with understanding the functional aspect of the relationship between GPO's and PowerShell, or really anything that helps broaden PowerShell's capabilities which can be initiated via the command line (trying to make this script as self-sufficient and reusable as possible) would be greatly appreciated. Here's the script so far with corresponding tasks.

1.) $cn = [ADSI]"WinNT://Inquisition"    
$user = $cn.Create("User","Test")   
$user.SetPassword("P@ssword!")
$user.setinfo()    
$user.description = "TestUser"    
$user.SetInfo()

2.) Get-WmiObject -Class Win32_UserAccount -Filter "name = 'Test'"  | Set-WmiInstance -Argument @{PasswordExpires = 0}

3.)?

4.) $Computername = "TEST1"

$sysinfo = Get-WmiObject Win32_ComputerSystem $sysinfo.JoinDomainOrWorkGroup("AWS-TEST")

5.) netsh advfirewall set allprofiles state off

6.) $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings    
$AUSettings.NotificationLevel    
$ausettings.NotificationLevel = 1    
$ausettings.save()

7.) $path = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'    
$name = 'start page'    
$value = 'http://www.blueprintcss.org/tests/parts/sample.html'    
Set-Itemproperty -Path $path -Name $name -Value $value

8.)?
  1. Add a new user account named “Test” with a password of “P@ssw0rd!”

  2. Set the password for account “Test” to never expire

  3. Add user “Test” to the local Administrators security group

  4. Set the computer name to be “TEST1” and the workgroup to “AWS-TEST”

  5. Turn the Windows Firewall Off

  6. Turn Windows Updates off and set to never check for updates

  7. Set company website as the default webpage in Internet Explorer

  8. Turn off the pop-up blocker in Internet Explorer

I had a similar need once, except mine was to remove local admin rights. This was the core of what worked for me.... Since your new, make sure to predefine your variables for Domain name, Host name, and User. Hope this helps!

    $AdminGroup = [ADSI]"WinNT://$HostName/Administrators,group"
    $InUser = [ADSI]"WinNT://$DomainName/$User,user"
    $Admingroup.Add($InUser.Path)

这是来自https://community.spiceworks.com/topic/post/3297687的单个衬板

([ADSI]"WinNT://<computername>/Administrators,group").Add("WinNT://<domain>/<user>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM