使用 Powershell 和 ADSI 设置本地密码
Using Powershell and ADSI to set local passwords
我正在尝试在 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"
我正在尝试在 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 = [adsi]"WinNT://$computer/$account,user"