1. シンプルな例
1.1. スクリプト
1 |
PS > Get-ChildItem -File -Recurse -Include *.c, *.h | Measure-Object |
1 |
Get-ChildItem -File -Recurse | Get-ACL | Where-Object {$_.Owner -like"*chihaya"} | Format-Table -property Owner, Path -Wrap |
1 |
ls -file -recurse | get-acl | ? {$_.Owner -like "*chihaya"} | format-table -property owner, path -wrap |
1 |
PS > gci -recurse -file -include *.c, *.h | % { (cat $_) -join "`r`n" | sc $_ } |
1 2 3 4 5 6 7 8 9 10 |
PS > Get-Alias CommandType Name Version Source ----------- ---- ------- ------ Alias % -> ForEach-Object Alias ? -> Where-Object Alias ac -> Add-Content Alias asnp -> Add-PSSnapin Alias cat -> Get-Content ... |
1 |
PS > Get-Alias | Where-Object { $_.Definition -eq "Get-ChildItem" } |
1 2 3 4 5 6 7 |
PS > gal | ? { $_.Definition -eq "Get-ChildItem" } CommandType Name Version Source ----------- ---- ------- ------ Alias dir -> Get-ChildItem Alias gci -> Get-ChildItem Alias ls -> Get-ChildItem |
PowerShellのprofileファイル “Microsoft.PowerShell(ISE)_profile.ps1” を作成する。
※ sh の ".profile
" や bash の ".bash_profile
" に相当するPowerShellの設定ファイル
profileファイルの場所は $profile で、あらかじめパスが指定されている。
profileファイルを置くフォルダを調べる方法から説明する。
1 2 |
PS C:\> $profile C:\Users\JaneDoe\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
1 2 |
PS C:\> $profile C:\Users\JaneDoe\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1 |
PowerShellでファイルを検索する方法
PowerShellにおいてコマンドレットのヘルプを表示する方法
続きを読む
コマンドラインプログラム nkf32 に, PowerShellのパイプラインを使って引数を渡す例
1 |
Get-ChildItem -Name -Recurse -File -Include *.c, *.h | %{echo $_; &"C:\Program Files (x86)\nkf\nkf32.exe" -g $_} |
※ サブディレクトリ下の *.c
と *.h
を再帰的に検索して文字コードを判定( -g
)する。
&演算子 / Call operator を利用する。
1 |
PS: > &"C:\Program Files (x86)\nkf\nkf32.exe" -g readme.txt |
-g : guess (文字コードの推定)