Powershell 无法通过Azure Automation更改VM的密码
我创建了一个Powershell脚本,其中包含函数“RandomPassword”,用于随机生成密码。但是,我无法将用户密码设置为随机生成的密码。下面是我遇到的PS脚本和错误- PSScript-Powershell 无法通过Azure Automation更改VM的密码,powershell,Powershell,我创建了一个Powershell脚本,其中包含函数“RandomPassword”,用于随机生成密码。但是,我无法将用户密码设置为随机生成的密码。下面是我遇到的PS脚本和错误- PSScript- Function RandomPassword { $ABC="A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" $abc="a","b","c
Function RandomPassword {
$ABC="A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
$abc="a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"
$char="!","@","#","$","%","*"
$num="1","2","3","4","5","6","7","8","9","0"
$Upper=Get-Random -count 1 -InputObject $ABC
$Lower=Get-Random -count 5 -InputObject $abc
$Char=Get-Random -count 1 -InputObject $char
$Num=Get-Random -count 1 -InputObject $num
$All=Get-Random -Count 7 -InputObject ($Lower+$Char+$Num)
$Raw=$All -join("")
$Temppassword = $Upper + $Raw
$Temppassword
}
$RandomPassword=RandomPassword
$RandomPassword
Set-ADAccountPassword -Reset -NewPassword $RandomPassword -Identity <username>
我也使用了这一行,但它没有帮助,我收到相同的错误
$SecPaswd=ConvertTo-SecureString -String $RandomPassword -AsPlainText -Force
有什么办法可以实现吗?任何帮助都将不胜感激 基于此错误,我认为建议的解决方案会有所帮助,并且不可能得到与
$SecPaswd
确实属于System.Security.SecureString类型相同的错误
当然,您还应该更改行中的参数:
Set-ADAccountPassword -Reset -NewPassword $RandomPassword -Identity <username>
Set ADAccountPassword-Reset-NewPassword$RandomPassword-Identity
其中,
$RandomPassword
应更改为$SecPaswd
您好,谢谢您的回复。这已经试过了。当我使用“$SecPaswd=converttosecurestring-String$RandomPassword-AsPlainText-Force”时,我将脚本更改为“Set ADAccountPassword-Reset-NewPassword$SecPaswd-Identity”。当我收到同样的错误时,你能用你在脚本中尝试过的东西更新你的问题脚本吗?我预计会出现一个与前面提到的稍有不同的错误,因为该错误以纯文本形式提及密码,而我预计将$SecPaswd传递给函数时,该错误不可能提及字符串纯文本。
Set-ADAccountPassword -Reset -NewPassword $RandomPassword -Identity <username>