PowerShell:创建本地用户帐户 [英] PowerShell: Create Local User Account

查看:63
本文介绍了PowerShell:创建本地用户帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个新的本地用户帐户,然后将它们添加到本地管理员组.这可以在 PowerShell 中完成吗?

I need to create a new local user account, and then add them to the local Administrators group. Can this be done in PowerShell?

# Create new local Admin user for script purposes
$Computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"

$LocalAdmin = $Computer.Create("User", "LocalAdmin")
$LocalAdmin.SetPassword("Password01")
$LocalAdmin.SetInfo()
$LocalAdmin.FullName = "Local Admin by Powershell"
$LocalAdmin.SetInfo()
$LocalAdmin.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
$LocalAdmin.SetInfo()

我有这个,但想知道是否还有更多 PowerShell 风格的东西.

I have this, but was wondering if there is anything more PowerShell-esque.

推荐答案

另一种选择是旧学校 NET USER 命令:

Another alternative is the old school NET USER commands:

NET USER 用户名密码"/ADD

好的 - 您不能设置所有选项,但对于简单的用户创建和操作来说,它的复杂性要低得多.易于在 Powershell 中编写脚本.

OK - you can't set all the options but it's a lot less convoluted for simple user creation & easy to script up in Powershell.

NET LOCALGROUP "group" "user"/add 设置组成员资格.

这篇关于PowerShell:创建本地用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆