我需要将安全字符串作为参数传递给Invoke-AzVMRunCommand。我的代码是
$pass=Read-Host "Enter Password for sysadmin" -AsSecureString
$stdstring = ConvertFrom-SecureString $pass
$runcmdparameters=@{
"sysadmincredential"=$stdstring
}
Invoke-AzVMRunCommand -ResourceGroupName $ServerResourceGroupName -VMName $VMVame -ScriptPath $TemplateFile -CommandId 'RunPowerShellScript' -Parameter $runcmdparameters -Verbose
Invoke-AzVMRunCommand脚本
Param(
[parameter(Mandatory=$true)][string]$sysadmincredential
)
$cr=ConvertTo-SecureString $sysadmincredential
Out-File "C:\Temp\log.txt" -InputObject $cr -Append
但是,脚本失败并显示
ConvertTo-SecureString:系统找不到指定的路径。 在 C:\ Packages \ Plugins \ Microsoft.CPlat.Core.RunCommandWindows \ 1.1.0 \ Downloads \ s cript11.ps1:4 char:5 + $ cr = ConvertTo-SecureString $ sysadmincredential + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [ConvertTo-SecureString],C ryptographicException + FullyQualifiedErrorId:ImportSecureString_InvalidArgument_Cryptographic
错误,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
谢谢