[英]Unable to change password of a VM through Azure Automation
I have a created a Powershell script with Function "RandomPassword" to randomly generate a password. 我创建了一个带有功能“ RandomPassword”的Powershell脚本,以随机生成一个密码。 But, I am unable to set the user password to randomly generated password.
但是,我无法将用户密码设置为随机生成的密码。 Below is the PS script and error I am encountering -
以下是我遇到的PS脚本和错误-
PSScript - 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>
Error - 错误-
Set-ADAccountPassword : Cannot bind parameter 'NewPassword'. Cannot convert the "qkqjh#8w" value of type "System.String" to
type "System.Security.SecureString".
I have also used this line, but it did not not help and I am receiving same error 我也使用了这一行,但是它没有帮助,我收到了同样的错误
$SecPaswd=ConvertTo-SecureString -String $RandomPassword -AsPlainText -Force
Is there a way I could achieve it? 有办法可以实现吗? Any help would be appreciated.
任何帮助,将不胜感激。
Based on the error, I would say that the suggested solution would help and it would not be possible to get the same error as $SecPaswd
is indeed of the type System.Security.SecureString. 基于该错误,我想说建议的解决方案将有所帮助,并且不可能获得与
$SecPaswd
确实属于System.Security.SecureString类型的错误相同的错误。
You should of course also change the Parameter in the line: 当然,您还应该更改以下行中的参数:
Set-ADAccountPassword -Reset -NewPassword $RandomPassword -Identity <username>
where $RandomPassword
should be changed to $SecPaswd
. 其中
$RandomPassword
应该更改为$SecPaswd
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.