2015-07-21 27 views
1

我試圖在Windows 2008服務器上自動設置一堆本地用戶帳戶的密碼。我已經嘗試了一些東西,這個工程如果我不使用變量這樣的用戶名:使用Powershell和ADSI設置本地密碼

$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() 
} 

我得到當我使用$帳戶變量的用戶(從文本文件列表)的錯誤是:

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

感謝您的幫助......

回答

3

似乎您的機器嘗試將$account值解析爲本地組名稱。

您可以指定它是你想要一個User object,用逗號和字符串user以下的帳戶名稱:

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

謝謝你 - 這做到了! –

相關問題