如何通过 PowerShell 命令行将本地用户变成管理员?

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

这里是 PowerShell 新手,我正在编写一个脚本,准备新安装的 PC 与我的 IT 公司网络合并。一项任务 我在将通过 PowerShell 创建的本地用户帐户转变为本地管理员时遇到了问题。

我使用 PowerShell 执行此操作至关重要,但我在研究中还没有遇到任何问题。此外,任何有助于理解 GPO 和 PowerShell 之间关系的功能方面的帮助,或者实际上任何有助于扩展 PowerShell 可通过命令行启动的功能的功能(试图使该脚本尽可能自给自足和可重用)都会非常有用赞赏。这是到目前为止包含相应任务的脚本。

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. 添加一个名为“Test”的新用户帐户,密码为“P@ssw0rd!”

  2. 将帐户“Test”的密码设置为永不过期

  3. 将用户“Test”添加到本地管理员安全组

  4. 将计算机名称设置为“TEST1”,将工作组设置为“AWS-TEST”

  5. 关闭 Windows 防火墙

  6. 关闭 Windows 更新并设置为从不检查更新

  7. 将公司网站设置为 Internet Explorer 中的默认网页

  8. 关闭 Internet Explorer 中的弹出窗口阻止程序

我曾经有过类似的需求,只是我的需求是删除本地管理员权限。这是对我有用的核心……因为你是新的,确保预定义域名、主机名和用户的变量。希望这对您有所帮助!

    $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>")