![](/img/trans.png)
[英]Accessing an azure vm through Powershell remote from Azure Automation
[英]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.