是否可以使用PowerShell更改Windows XP(无Active Directory)上的本地用户设置,特别是用户属性选项卡上的设置 – 例如“密码永不过期”以及用户所属的组?
示例会很好,但是指向相关文档的指针也会非常棒 – 我甚至不知道要查找什么。
最简单的方法是将ADSI查询定向到本地WinNT提供程序 – 这将返回您感兴趣的系统上的本地对象。这些对象可以是本地系统或远程系统,但是将附加到本地帐户和安全对象,而不是AD。
$user = [ADSI]"WinNT://joe-pc/joe"
用这个,你可以查询和修改$ user对象的属性。
要设置“密码不过期”标志,您需要在UserFlags属性中设置相关标志。 您可以在Motobit这里find这些有用的表格。
从以上示例中强制设置Joe的帐户密码永不过期:
$Never_Expire=0x10000 $user.UserFlags.value=$user.UserFlags.value -bor $Never_Expire
修改组成员资格有一点涉及,但微软的PowerShell Guy有一步一步的步骤, 虽然将域用户帐户添加到我认为正是您需要的系统上的本地组 。
inheritance人一种方法来closures密码永不过期连接到每台机器..
http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/3836/afv/topic/Default.aspx
PS版本2.0
$user = [ADSI]"WinNT://ComputerName/User" $user.UserFlags = 65536 // Flag value used to set password to not expire $user.SetInfo()
伟大的参考 – http://learningpcs.blogspot.com/2011/01/powershell-winnt-provider.html
我不确定如何完全按照您的要求进行操作,但MS入门文档位于以下位置: http : //www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/start.mspx
这些都没有为我工作,所以经过多次search和大量的试验和错误我想出了这个删除password never expires从本地pipe理员帐户,基于SID和本地来宾帐户,基于SID。
#Set local administrator's password to expire $admin = (gwmi -query "Select * From Win32_UserAccount Where LocalAccount = TRUE AND SID LIKE 'S-1-5%-500'").Name wmic useraccount where "name='$admin'" set passwordexpires=true #Set local guest's password to machine expire $guest = (gwmi -query "Select * From Win32_UserAccount Where LocalAccount = TRUE AND SID LIKE 'S-1-5%-501'").Name wmic useraccount where "name='$guest'" set passwordexpires=true