PowerShell添加本地账户脚本分享

时间:2022-10-28 13:03:47

脚本源码:

复制代码 代码如下:

$nt=[adsi]"WinNT://localhost"
$user=$nt.create("user","test")
$user.setpassword("password")
$user.setinfo()
Get-WmiObject -Class Win32_UserAccount -Filter "name = 'test'" | Set-WmiInstance -Argument @{PasswordExpires = 0}
$group=[ADSI]"WinNT://localhost/administrators,group"
$group.add("WinNT://localhost/test")