2011-11-23から1日間の記事一覧

PowerShellのNULLチェックは -eq $null 

PowerShell では、$null という名前の特殊な変数で表します。 $var = Get-ChildItem *.txt | Select-Object Name if( $var -eq $null ){ Write-Host "No files" } ネタ元 http://ufcpp.net/study/powershell/variable.html

PowerShellの終了はexit

exit

PowerShellのコメントは#

文字列のスプリットは .split()

MSH C:\> "Microsoft Command Shell".split() Microsoft Command Shellネタ元 http://d.hatena.ne.jp/newpops/20051010/p1

特殊文字 改行コードは「`n」

エスケープ・シーケンス `b バックスペース `n 改行 `r キャリッジ・リターン `t タブ ネタ元 http://www.atmarkit.co.jp/fwin2k/operation/psh02/psh02_02.html

ファイル出力 "ファイルに書き込む文字列" | Out-File "出力ファイルパス"

PS C:\Work> "あいうえお" | Out-File sample.txt -encoding UTF8エンコード指定しないとUTF-16になるみたい。 これだとCSVで出力してもexcelでうまく認識しない。 ネタ元 http://hiros-dot.net/PowerShell/file/file04.htm

ファイル読み取って1行ずつ処理

Get-Content ./hogelist.txt | Foreach-Object { echo $_ } ネタ元 http://d.hatena.ne.jp/moto0215/searchdiary?word=%2A%5Bpowershell%5D

ファイル名の変更は Rename-Item 名前を変更する項目のパス -newName 項目の新しい名前

ネタ元 http://hiros-dot.net/PowerShell/file/file21.htm