使用 powershell 创建本地 windows 用户,仅用作 运行 服务的服务用户

Create a local windows user using powershell to be used just as a service user to run services

如何使用 powershell 脚本创建本地用户。 用户应该无法登录。该用户的目的只是为了分配给系统中安装的运行几个服务。

谢谢

下面是我按照underlaying COM component object model and the IADsUser interface使用的方式。您必须 运行 作为管理员。

$obj = [ADSI]"WinNT://$env:COMPUTERNAME"
$user1=$obj.create("user", "utilisateur1")
$user1.PasswordExpired=0
$user1.Invoke("setpassword","test.2012")
$user1.Invoke("put", "HomeDirectory", "c:\silogix")
$user1.Invoke("put", "Profile", "c:\docs")
$user1.Invoke("put", "LoginScript", "test.cmd")
$user1.CommitChanges()

您可以在this answer中看到结果。我只是复制我的答案,因为它不是真正的重复。