gpt4 book ai didi

powershell - 生成随 secret 码

转载 作者:行者123 更新时间:2023-12-02 17:59:59 24 4
gpt4 key购买 nike

我在 PowerShell 中有这个脚本。我想为每个从文件导入的用户设置随 secret 码,并且我希望弹出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"

最佳答案

您可以使用静态 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"

关于powershell - 生成随 secret 码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40466124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com