繁体   English   中英

无法通过Azure自动化更改VM的密码

[英]Unable to change password of a VM through Azure Automation

我创建了一个带有功能“ RandomPassword”的Powershell脚本,以随机生成一个密码。 但是,我无法将用户密码设置为随机生成的密码。 以下是我遇到的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","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>

错误-

Set-ADAccountPassword : Cannot bind parameter 'NewPassword'. Cannot convert the "qkqjh#8w" value of type "System.String" to 
type "System.Security.SecureString".

我也使用了这一行,但是它没有帮助,我收到了同样的错误

$SecPaswd=ConvertTo-SecureString -String $RandomPassword -AsPlainText -Force

有办法可以实现吗? 任何帮助,将不胜感激。

基于该错误,我想说建议的解决方案将有所帮助,并且不可能获得与$SecPaswd确实属于System.Security.SecureString类型的错误相同的错误。

当然,您还应该更改以下行中的参数:

Set-ADAccountPassword -Reset -NewPassword $RandomPassword -Identity <username>

其中$RandomPassword应该更改为$SecPaswd

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM