2011年8月4日木曜日

PowerShell メモ

  • コマンドプロンプト(or バッチファイル)からコマンドを指定して実行
    C:\> powershell -Command コマンド群
    ※ クォートやエスケープはいらない。
    ※ 複数のコマンドは ";" で分割
  • コマンドプロンプト(or バッチファイル)からスクリプトを呼び出す
    C:\> powershell -ExcecutionPolicy RemoteSigned -File スクリプト.ps1
  • パスワードを入力させる
    PS> $password = read-host Password -AsSecureString Password: 123456789 PS> $password System.Security.SecureString
    ※ 直接文字列は取得できない
  • [System.Security.SecureString] から文字列を取得する
    PS> $ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password) PS> [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr) 123456789

参照

  • ユーザに文字列を入力させる(1)/(2) - PowerShell Memo
    → http://d.hatena.ne.jp/newpops/20050922/p1
    → http://d.hatena.ne.jp/newpops/20050923/p1