下面是我必須從 linux VM 獲取資料的代碼。
$username = Read-Host "Please enter VM Admin user Name"
$password = Read-Host -assecurestring "Please enter VM Admin password"
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
$plinkpath = 'C:\Program Files\PuTTY\'
$servername = Read-Host "Please enter targeted linux VM IP Address"
$cmd = 'df -h'
$diskinfo = @(echo y | &($plinkpath "plink.exe") -pw $password $username@$servername $cmd)
如果我像這樣傳遞密碼,我將無法獲得命令的輸出,但是當我將密碼作為原始字串發送時
$password = Read-Host "Please enter VM Admin password"
我能夠獲得命令的輸出。
請讓我知道這是什么原因。
uj5u.com熱心網友回復:
原因是-assecurestring應該顯示*而不是鍵入的輸出。
有關更多資訊,請參閱Read-Host MS 手冊。
為了更好的可讀性:
$password = Read-Host "Please enter VM Admin password" -AsSecureString
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/363113.html
標籤:电源外壳
