デフォルトのエイリアスとかぶってるコマンド

コマンドプロンプトで使っていたコマンドを PowerShell で実行しようとすると、時々エイリアスとかぶってるやつがあることに気づく。そういう時は後ろに .exe を付ければ実行できる。PowerShellに専用のコマンドレットもあるのだが、その場でタイプして実行する用途としてはそれほど使いやすくはなかったりする。

sc.exe

サービスを制御するためのコマンドです(TechNet)。

Set-Contentエイリアスとかぶってます。

サービスの制御なら *-Service 系のコマンドで代替できます。

# サービスの状態を確認
sc.exe query sysmain
↓
# PowerShell
Get-Service sysmain | Format-List
gsv sysmain | fl
# サービスの停止
sc.exe stop spooler
↓
# PowerShell
Stop-Service spooler
spsv spooler

where.exe

ファイルの検索コマンドです(TechNet)。

Where-Objectエイリアスとかぶってます。

ファイルを探すなら Get-CommandGet-ChildItem で代替できます。

# パスの通っている場所からコマンドを検索
where.exe notepad
↓
# PowerShell
Get-Command notepad -all
gcm notepad -all
# 特定のディレクトリ以下からファイルを検索
where.exe /r . *.txt
↓
# PowerShell
Get-ChildItem -Recurse *.txt | Select-Object FullName
gci -re *.txt | select fullname

fc.exe

ファイルの中身を比較するコマンドです(TechNet)。

Format-Customエイリアスとかぶってます。

Compare-Object でも一応ファイルの比較はできますが、fc.exe ほど出力される情報は多くありません。

Compare-Object (Get-Content foo.txt) (Get-Content bar.txt)
compare (gc foo.txt) (gc bar.txt)

そもそも実際にやりたいことは、ファイルの中身が同じか否か確認したいだけでしょうから、その場合はファイルのハッシュ値を計算させた方が手っ取り早いでしょう。

Get-FileHash foo.txt, bar.txt