■このサイトはPowerShell(MSH/Monad)奮闘記です
管理人「newpops(吉岡洋)」が「PowerShell(旧名:MSH/Monad)」の研究結果を日々綴っていきます。
【お知らせ】
この日記からPowerShellのTipsを抽出し「PowerShell FAQ」として整理しました。
2005-09-23
■[MSH]ユーザに文字列を入力させる(2)
ユーザに文字列を入力させる(1) - PowerShell Memoの続きです。
SecureStringとは?
「read-host」の「SecureString」オプションを使うと、戻り値の型は「System.Security.SecureString」になります。
「SecureString」はメモリ上で暗号化されるセキュアなオブジェクトです。
MSH C:\> $password = read-host EnterPassword -SecureString EnterPassword: ******* MSH C:\> $password System.Security.SecureString
パスワードを格納した変数を表示しようとすると、「System.Security.SecureString」と表示され、内容は分かりません。
SecureStringの操作方法
SecureStringを操作するには「System.Runtime.InteropServices.Marshal」クラスを利用します。
MSH C:\> $password = read-host EnterPassword -SecureString EnterPassword: ******* MSH C:\> $ptr = [System.Runtime.InteropServices.Marshal] ::SecureStringToBSTR($password) MSH C:\> [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr) newpops
- SecureStringToBSTRメソッド
- PtrToStringBSTRメソッド
- BSTR 文字列をコピーします。(戻り値:String)



