2016-11-07 7 views
2

私はこのスクリプトをPowerShellに持っています。私はファイルからの各ユーザーのインポートのためのランダムなパスワードを設定したい、私は他のtxtファイルに保存したいポップアップcmdのすべてのコメントが欲しい。どうしたらいいですか?ランダムパスワードを生成

# 
# Description: Enable accounts, reset passwords and set change password option at first logon. 
# 
Import-Module ActiveDirectory 
# Set default password "XXX" 
$password = ConvertTo-SecureString -AsPlainText “XXX” -Force 
# get account list from UserList.txt 
# 1 user per line 
$users = Get-Content -Path 'G:\Shares\XXX\ResetPassword\UserList.txt' 
ForEach ($user in $users) 
{ 
# Set default password for account 
Get-ADUser $user | Set-ADAccountPassword -NewPassword $password -Reset 
# Set option to change password at first logon 
Get-ADUser $user | Set-AdUser -ChangePasswordAtLogon $true 
# Enable account 
Enable-ADAccount -Identity $user 
Write-Host “Password change for: $user” 
} 
Write-Host “New password for all users: XXX” 
# ————- End ———– 
Read-Host -Prompt "Click enter to quit" 
+0

ますすべてのユーザーに同じパスワードを与えていますか? – Nkosi

+0

はい、でも今は各ユーザのランダムなパスワードを与えたい –

答えて

6

パスワードを生成する静的GeneratePasswordメソッドを使用することができます。

Add-Type -AssemblyName System.Web 
[System.Web.Security.Membership]::GeneratePassword(10, 3) 

編集:あなたがあなたのスクリプトを変更する必要が

# 
# Description: Enable accounts, reset passwords and set change password option at first logon. 
# 
Import-Module ActiveDirectory 
Add-Type -AssemblyName System.Web 
$unsecuredPwd = [System.Web.Security.Membership]::GeneratePassword(10, 3) 
# Set default password "XXX" 
$password = ConvertTo-SecureString -AsPlainText $unsecuredPwd -Force 
# get account list from UserList.txt 
# 1 user per line 
$users = Get-Content -Path 'G:\Shares\XXX\ResetPassword\UserList.txt' 
ForEach ($user in $users) 
{ 
# Set default password for account 
Get-ADUser $user | Set-ADAccountPassword -NewPassword $password -Reset 
# Set option to change password at first logon 
Get-ADUser $user | Set-AdUser -ChangePasswordAtLogon $true 
# Enable account 
Enable-ADAccount -Identity $user 
Write-Host "Password change for: $user" 
} 
Write-Host "New password for all users: $unsecuredPwd" 
# ————- End ———– 
Read-Host -Prompt "Click enter to quit" 
+0

どこにこのコマンドを設定する必要がありますか? –

+0

'$ password = ConvertTo-SecureString -AsPlainText([System.Web.Security.Membership] :: GeneratePassword(10、3))-Force' –

+0

私の編集した答えを見てください。 –

関連する問題