我在PowerShell中有此腳本。我想爲每個用戶從文件導入設置隨機密碼,我希望在彈出式cmd中的所有註釋我想保存在其他txt文件中。我怎樣才能做到這一點?生成隨機密碼
#
# 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"
你給所有用戶提供相同的密碼? – Nkosi
是的,但現在我想給每個用戶的隨機密碼 –