Windows PowerShell を使う

            丹野 嘉信
  http://ytanno.herokuapp.com/
Windows PowerShell とは
• Windows PowerShell は、マイクロソフトが
  開発した拡張可能なコマンドラインイン
  ターフェース (CLI) シェルおよびスクリプ
  ト言語
                         Wikipediaより
使うきっかけ
• Windows上でlsコマンドが使いたかった
似たようなツール
• Cygwin
普通に使うならこれ。ただ容量が重い

• Gow
容量は軽いが日本語が文字化けする
直す方法はあるらしいが見つからなかった\
(^o^)/
Windows PowerShellの利点と欠
            点
利点
• lsの出力結果で日本語が化けない
• .net を利用してスクリプトがかける
• Windows7にデフォルトでついている

欠点
• Linuxのコマンドと違う。⇒aliasでOK
使ってみよう
• ウィンドウズキーを押す
• 検索Boxに「Windows
  PowerShell」
• Windows PowerShellをクリック

• あとはお好みでショートカット
  やタスクバーに表示を選択
lsコマンド
• 青っぽい画面が出たらlsと打つ
コマンドの違い
• Get-alias
• 実際は右側のコマンドが呼ばれている




• lsはGet-ChildItemでした
Aliasの設定
• Linuxっぽく変更したい人向け
• Set-Alias 変更したいコマンド 実際の名前
• 例 Set-Alias which get-command

この設定だとPowerShellを止めたら、効果が
消えてしまう
起動時実行の設定
• まずはGet-Variable $profile
• プロファイルのパスが表示されます。
(起動時に命令を読み込んでくれます)




• ない時は自分で作るか
• コマンド New-Item -path $profile -type file -
  force
設定方法
• notepad $profile
• 起動したメモ帳に編集




• WindowsPowerShellを立ち上げなおす
• エラーが返ってくる
エラーの回避
• デフォルトではスクリプトが無効になってい
  ます

• Set-ExecutionPolicy RemoteSigned
で回避可能
パラメータの詳細は
http://www.atmarkit.co.jp/fwin2k/operation/psh02
/psh02_01.html
に書いてあります。
再度立ち上げなおす
• 成功!
Aliasの例
• Linuxのものと挙動が違うものがあります
• 参考程度にしてくだい

Set-Alias d Get-Date
Set-Alias which get-command
Set-Alias grep Select-String
Set-Alias chmod attrib

Set-Location C:UserstannoDesktop


Get-Variable profile
おまけ
• Git-Bashのように使いたい!

PowerShellでGit
http://devadjust.exblog.jp/17296786/

1 Posh-GitをGItHubからダウンロード
2 install.ps1を任意の場所に配置
3 install.ps1を実行後、reload

Profileに自動的に追加される
よく使いそうなコマンド
•   findStr
•   cp
•   tasklist
•   ps
•   Get-alias
その他参照
Windows PowerShell プロファイル
http://technet.microsoft.com/ja-
jp/scriptcenter/powershell_owner06.aspx

Windows PowerShellコマンド&スクリプティ
ング入門(後編)
http://www.atmarkit.co.jp/fwin2k/operation/ps
h02/psh02_01.html
ご清聴ありがとうございまし
      た

Power shellmemo