2016-12-07 104 views
0

是否有任何PowerShell腳本在Windows Server 2003中停用Windows用戶(從CSV文件)禁用Windows用戶(從CSV文件)?這些Windows用戶是本地用戶帳戶(非AD帳戶)。事實上,我發現了很多這樣的AD腳本。你的建議非常感謝。PowerShell腳本在Windows Server 2003

回答

1

這會幫助你。請根據您的要求更換佔位符:

$EnableUser = 512 
$DisableUser = 2 
$PasswordNotExpire = 65536 # password never expires 
$PasswordCantChange = 64 # passwords cannot be changed 
$users = Import-Csv "path\Users_to_disable.csv" # I believe you have only single column else you have to pick the column 
$computer = $env:COMPUTERNAME 

Foreach($user in $users){ $user = [ADSI]"WinNT://$computer/$user" 
$user.userflags = $DisableUser+$PasswordNotExpire+$PasswordCantChange 
#$user.Userflags = $EnableUser+$PasswordNotExpire+$PasswordCantChange 
$user.setinfo() 
} 
+0

謝謝@Ranadip!讓我試試看。 –

+0

@KyawThurein:接受答案,如果它可以幫助你。 –

+0

+1 @Ranadip。在[ADSI]「WinNT:// $ computer/$ user」之前添加$ user = $ user。{csv_column_name}解決了問題!謝謝 –