我正在尝试在Windows 2008服务器上自动设置一堆本地用户帐户的密码。我已经尝试了一些方法,并且如果我不对用户名使用变量,则可以这样做:
$user = [adsi]"WinNT://$computer/SomeUserName"
我的脚本块在下面...任何想法我在做什么错?
$accounts = Get-Content c:\userlist.txt
$computer = SomeComputerName
$password = "MyPassword"
Foreach($account in $accounts)
{
$user = [adsi]"WinNT://$computer/$account"
$user.SetPassword("$Password")
$user.SetInfo()
}
当我为用户使用$ account变量时(从文本文件列表中),我得到的错误是:
The following exception occurred while retrieving member "SetInfo": "The group name could not be found.
谢谢你的帮助...
最佳答案
看来您的计算机尝试将$account
值解析为本地组名。
您可以通过在帐户名后面加上逗号和字符串user
来指定它为所需的User object:
$user = [adsi]"WinNT://$computer/$account,user"
关于powershell - 使用Powershell和ADSI设置本地密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31549493/