使用 Powershell 和 ADSI 设置本地密码 [英] Using Powershell and ADSI to set local passwords

查看:28
本文介绍了使用 Powershell 和 ADSI 设置本地密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 2008 服务器上自动设置一堆本地用户帐户的密码.我已经尝试了一些事情,如果我不使用这样的用户名变量,这会起作用:

I'm trying to automate setting a bunch of local user accounts' password on a Windows 2008 server. I've tried a few things and this works if I don't use a variable for the username like this:

 $user = [adsi]"WinNT://$computer/SomeUserName"

我的脚本块在下面...知道我做错了什么吗?

My script block is below... any ideas what I'm doing wrong?

$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 error I get when I use the $account variable for the user (from the text file list) is:

The following exception occurred while retrieving member "SetInfo": "The group name could not be found.

感谢您的帮助...

推荐答案

您的机器似乎试图将 $account 值解析为本地组名称.

It seems that your machine tries to resolve the $account value to a local group name.

您可以指定它是一个 用户对象 你想要的,在帐户名后面加一个逗号和字符串 user:

You can specify that it is a User object you want, by following the account name with a comma and the string user:

$user = [adsi]"WinNT://$computer/$account,user"

这篇关于使用 Powershell 和 ADSI 设置本地密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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