📖

PowerShellコマンドレットのエイリアス一覧(バージョン5.1と7.3.6で確認)

2023/08/31に公開

概要

PowerShellのコマンドレットは、「 Get-Set-Remove-New- 」などの文字から始まるコマンド(たとえばプロセスを確認するコマンドは Get-Process )があります。
一方、UnixやLinuxのコマンド(UnixやLinuxのプロセス確認コマンドはps)と比較すると、PowerShellのコマンドレットは長い文字列で構成されたコマンドと言えるでしょう。

CLIでコマンドレットを入力すると1回いっかい長い文字列のコマンドを打つ必要がある為、時間がかかり面倒。
そんなケースの時、短い文字列のコマンド、エイリアス(別名)を活用する事で時短につながります。

今回は以前から気になっていたPowerShellコマンドレットのエイリアスを調べ表形式で紹介。
なお、確認するPowerShellのバージョンはWindows標準で導入されているバージョン5.1と2023年8月現在、最新バージョンである7.3.6が対象です。

この記事のターゲット

  • PowerShellユーザーの方
  • 下記の環境下におけるPowerShellコマンドレットのエイリアスを把握したい方
    • Windows標準のPowerShell:5.1
    • 2023年8月現在、最新のPowerShell:7.3.6

環境

PowerShell 5.1(環境)

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\WINDOWS\system32>

PowerShell 7.3.6(環境)

PS D:\Downloads\PowerShell-7.3.6-win-x64> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS D:\Downloads\PowerShell-7.3.6-win-x64>

エイリアス一覧

コマンド結果の生データ(省略あり)

表形式に変換したコマンド結果を後述するので、ここでの生データ(Raw data)は先頭付近のみ記載し、それ以降の結果は省略しています。

コピー用
Get-Alias

PowerShell 5.1(Get-Aliasコマンドレット)

PS C:\WINDOWS\system32> Get-Alias

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           % -> ForEach-Object
Alias           ? -> Where-Object
Alias           ac -> Add-Content
Alias           asnp -> Add-PSSnapin
Alias           cat -> Get-Content
Alias           cd -> Set-Location
 ~~~ 以降は省略(後述で表形式を紹介するため) ~~~

PS C:\WINDOWS\system32>

PowerShell 7.3.6(Get-Aliasコマンドレット)

PS D:\Downloads\PowerShell-7.3.6-win-x64> Get-Alias

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           ? -> Where-Object
Alias           % -> ForEach-Object
Alias           ac -> Add-Content
Alias           cat -> Get-Content
Alias           cd -> Set-Location
 ~~~ 以降は省略(後述で表形式を紹介するため) ~~~

PS D:\Downloads\PowerShell-7.3.6-win-x64>

表に変換したコマンド結果

必要な項目だけ抜粋しPowerShellコマンドレット(Definition)で昇順ソートした表。

PowerShell 5.1(表に変換)

表に変換したコマンド結果 - PowerShell 5.1 < クリックで折りたたみが開く >
PowerShellコマンドレット
(Definition)
エイリアス名
(Name)
公式リファレンス
(HelpUri)
Add-Content ac
Add-PSSnapIn asnp https://go.microsoft.com/fwlink/?LinkID=113281
Clear-Content clc
Clear-History clhy https://go.microsoft.com/fwlink/?LinkID=135199
Clear-Host clear https://docs.microsoft.com/powershell/module/microsoft.powershell.core/functions/clear-host?view=powershell-5.1&WT.mc_id=ps-gethelp
Clear-Host cls https://docs.microsoft.com/powershell/module/microsoft.powershell.core/functions/clear-host?view=powershell-5.1&WT.mc_id=ps-gethelp
Clear-Item cli
Clear-ItemProperty clp
Clear-Variable clv https://go.microsoft.com/fwlink/?LinkID=113285
Compare-Object compare https://go.microsoft.com/fwlink/?LinkID=113286
Compare-Object diff https://go.microsoft.com/fwlink/?LinkID=113286
Connect-PSSession cnsn https://go.microsoft.com/fwlink/?LinkID=210604
ConvertFrom-String CFS https://go.microsoft.com/fwlink/?LinkID=507579
Convert-Path cvpa
Copy-Item copy
Copy-Item cp
Copy-Item cpi
Copy-ItemProperty cpp
Disable-PSBreakpoint dbp https://go.microsoft.com/fwlink/?LinkID=113294
Disconnect-PSSession dnsn https://go.microsoft.com/fwlink/?LinkID=210605
Enable-PSBreakpoint ebp https://go.microsoft.com/fwlink/?LinkID=113295
Enter-PSSession etsn https://go.microsoft.com/fwlink/?LinkID=135210
Exit-PSSession exsn https://go.microsoft.com/fwlink/?LinkID=135212
Export-Alias epal https://go.microsoft.com/fwlink/?LinkID=113296
Export-Csv epcsv https://go.microsoft.com/fwlink/?LinkID=113299
Export-PSSession epsn https://go.microsoft.com/fwlink/?LinkID=135213
ForEach-Object % https://go.microsoft.com/fwlink/?LinkID=113300
ForEach-Object foreach https://go.microsoft.com/fwlink/?LinkID=113300
Format-Custom fc https://go.microsoft.com/fwlink/?LinkID=113301
Format-Hex fhx https://go.microsoft.com/fwlink/?LinkId=526919
Format-List fl https://go.microsoft.com/fwlink/?LinkID=113302
Format-Table ft https://go.microsoft.com/fwlink/?LinkID=113303
Format-Wide fw https://go.microsoft.com/fwlink/?LinkID=113304
Get-Alias gal https://go.microsoft.com/fwlink/?LinkID=113306
Get-ChildItem dir
Get-ChildItem gci
Get-ChildItem ls
Get-Command gcm https://go.microsoft.com/fwlink/?LinkID=113309
Get-Content cat
Get-Content gc
Get-Content type
Get-History ghy https://go.microsoft.com/fwlink/?LinkID=113317
Get-History h https://go.microsoft.com/fwlink/?LinkID=113317
Get-History history https://go.microsoft.com/fwlink/?LinkID=113317
Get-Item gi
Get-ItemProperty gp
Get-ItemPropertyValue gpv
Get-Job gjb https://go.microsoft.com/fwlink/?LinkID=113328
Get-Location gl
Get-Location pwd
Get-Member gm https://go.microsoft.com/fwlink/?LinkID=113322
Get-Module gmo https://go.microsoft.com/fwlink/?LinkID=141552
Get-Process gps
Get-Process ps
Get-PSBreakpoint gbp https://go.microsoft.com/fwlink/?LinkID=113325
Get-PSCallStack gcs https://go.microsoft.com/fwlink/?LinkID=113326
Get-PSDrive gdr
Get-PSSession gsn https://go.microsoft.com/fwlink/?LinkID=135219
Get-PSSnapIn gsnp https://go.microsoft.com/fwlink/?LinkID=113330
Get-Service gsv
Get-Unique gu https://go.microsoft.com/fwlink/?LinkID=113335
Get-Variable gv https://go.microsoft.com/fwlink/?LinkID=113336
Get-WmiObject gwmi
Group-Object group https://go.microsoft.com/fwlink/?LinkID=113338
help man https://go.microsoft.com/fwlink/?LinkID=113316
Import-Alias ipal https://go.microsoft.com/fwlink/?LinkID=113339
Import-Csv ipcsv https://go.microsoft.com/fwlink/?LinkID=113341
Import-Module ipmo https://go.microsoft.com/fwlink/?LinkID=141553
Import-PSSession ipsn https://go.microsoft.com/fwlink/?LinkID=135221
Invoke-Command icm https://go.microsoft.com/fwlink/?LinkID=135225
Invoke-Expression iex https://go.microsoft.com/fwlink/?LinkID=113343
Invoke-History ihy https://go.microsoft.com/fwlink/?LinkID=113344
Invoke-History r https://go.microsoft.com/fwlink/?LinkID=113344
Invoke-Item ii
Invoke-RestMethod irm https://go.microsoft.com/fwlink/?LinkID=217034
Invoke-WebRequest curl https://go.microsoft.com/fwlink/?LinkID=217035
Invoke-WebRequest iwr https://go.microsoft.com/fwlink/?LinkID=217035
Invoke-WebRequest wget https://go.microsoft.com/fwlink/?LinkID=217035
Invoke-WMIMethod iwmi
Measure-Object measure https://go.microsoft.com/fwlink/?LinkID=113349
mkdir md
Move-Item mi
Move-Item move
Move-Item mv
Move-ItemProperty mp
New-Alias nal https://go.microsoft.com/fwlink/?LinkID=113352
New-Item ni
New-Module nmo https://go.microsoft.com/fwlink/?LinkID=141554
New-PSDrive mount
New-PSDrive ndr
New-PSSession nsn https://go.microsoft.com/fwlink/?LinkID=135237
New-PSSessionConfigurationFile npssc https://go.microsoft.com/fwlink/?LinkID=217036
New-Variable nv https://go.microsoft.com/fwlink/?LinkID=113361
Out-GridView ogv https://go.microsoft.com/fwlink/?LinkID=113364
Out-Host oh https://go.microsoft.com/fwlink/?LinkID=113365
Out-Printer lp https://go.microsoft.com/fwlink/?LinkID=113367
Pop-Location popd
powershell_ise.exe ise
Push-Location pushd
Receive-Job rcjb https://go.microsoft.com/fwlink/?LinkID=113372
Receive-PSSession rcsn https://go.microsoft.com/fwlink/?LinkID=217037
Remove-Item del
Remove-Item erase
Remove-Item rd
Remove-Item ri
Remove-Item rm
Remove-Item rmdir
Remove-ItemProperty rp
Remove-Job rjb https://go.microsoft.com/fwlink/?LinkID=113377
Remove-Module rmo https://go.microsoft.com/fwlink/?LinkID=141556
Remove-PSBreakpoint rbp https://go.microsoft.com/fwlink/?LinkID=113375
Remove-PSDrive rdr
Remove-PSSession rsn https://go.microsoft.com/fwlink/?LinkID=135250
Remove-PSSnapin rsnp https://go.microsoft.com/fwlink/?LinkID=113378
Remove-Variable rv https://go.microsoft.com/fwlink/?LinkID=113380
Remove-WMIObject rwmi
Rename-Item ren
Rename-Item rni
Rename-ItemProperty rnp
Resolve-Path rvpa
Resume-Job rujb https://go.microsoft.com/fwlink/?LinkID=210611
Select-Object select https://go.microsoft.com/fwlink/?LinkID=113387
Select-String sls https://go.microsoft.com/fwlink/?LinkID=113388
Set-Alias sal https://go.microsoft.com/fwlink/?LinkID=113390
Set-Content sc
Set-Item si
Set-ItemProperty sp
Set-Location cd
Set-Location chdir
Set-Location sl
Set-PSBreakpoint sbp https://go.microsoft.com/fwlink/?LinkID=113449
Set-Variable set https://go.microsoft.com/fwlink/?LinkID=113401
Set-Variable sv https://go.microsoft.com/fwlink/?LinkID=113401
Set-WMIInstance swmi
Show-Command shcm https://go.microsoft.com/fwlink/?LinkID=217448
Sort-Object sort https://go.microsoft.com/fwlink/?LinkID=113403
Start-Job sajb https://go.microsoft.com/fwlink/?LinkID=113405
Start-Process saps
Start-Process start
Start-Service sasv
Start-Sleep sleep https://go.microsoft.com/fwlink/?LinkID=113407
Stop-Job spjb https://go.microsoft.com/fwlink/?LinkID=113413
Stop-Process kill
Stop-Process spps
Stop-Service spsv
Suspend-Job sujb https://go.microsoft.com/fwlink/?LinkID=210613
Tee-Object tee https://go.microsoft.com/fwlink/?LinkID=113417
Trace-Command trcm https://go.microsoft.com/fwlink/?LinkID=113419
Wait-Job wjb https://go.microsoft.com/fwlink/?LinkID=113422
Where-Object ? https://go.microsoft.com/fwlink/?LinkID=113423
Where-Object where https://go.microsoft.com/fwlink/?LinkID=113423
Write-Output echo https://go.microsoft.com/fwlink/?LinkID=113427
Write-Output write https://go.microsoft.com/fwlink/?LinkID=113427
参考情報:すべての項目を表示(一部省略) < クリックで折りたたみが開く >
HelpUri ResolvedCommandName DisplayName ReferencedCommand ResolvedCommand Definition Options Description OutputType Name CommandType Source Version Visibility ModuleName Module RemotingCapability Parameters ParameterSets
https://go.microsoft.com/fwlink/?LinkID=113300 ForEach-Object % -> ForEach-Object ForEach-Object ForEach-Object ForEach-Object ReadOnly, AllScope System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] % Alias Public None System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
https://go.microsoft.com/fwlink/?LinkID=113423 Where-Object ? -> Where-Object Where-Object Where-Object Where-Object ReadOnly, AllScope System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] ? Alias Public None System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
ac -> Add-Content Add-Content ReadOnly, AllScope ac Alias Public PowerShell
https://go.microsoft.com/fwlink/?LinkID=113281 Add-PSSnapin asnp -> Add-PSSnapin Add-PSSnapin Add-PSSnapin Add-PSSnapIn ReadOnly, AllScope System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] asnp Alias Public PowerShell System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
cat -> Get-Content Get-Content AllScope cat Alias Public PowerShell
cd -> Set-Location Set-Location AllScope cd Alias Public PowerShell
https://go.microsoft.com/fwlink/?LinkID=507579 ConvertFrom-String CFS -> ConvertFrom-String ConvertFrom-String ConvertFrom-String ConvertFrom-String None System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] CFS Alias Microsoft.PowerShell.Utility 3.1.0.0 Public Microsoft.PowerShell.Utility Microsoft.PowerShell.Utility PowerShell System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
~~~ 以降は省略 ~~~

PowerShell 7.3.6(表に変換)

表に変換したコマンド結果 - PowerShell 7.3.6 < クリックで折りたたみが開く >
PowerShellコマンドレット エイリアス名 公式リファレンス
Add-Content ac
Clear-Content clc
Clear-History clhy https://go.microsoft.com/fwlink/?LinkID=2096691
Clear-Host clear https://go.microsoft.com/fwlink/?LinkID=2096480
Clear-Host cls https://go.microsoft.com/fwlink/?LinkID=2096480
Clear-Item cli
Clear-ItemProperty clp
Clear-Variable clv https://go.microsoft.com/fwlink/?LinkID=2096923
Compare-Object compare https://go.microsoft.com/fwlink/?LinkID=2096605
Compare-Object diff https://go.microsoft.com/fwlink/?LinkID=2096605
Connect-PSSession cnsn https://go.microsoft.com/fwlink/?LinkID=2096694
Convert-Path cvpa
Copy-Item copy
Copy-Item cp
Copy-Item cpi
Copy-ItemProperty cpp
Disable-PSBreakpoint dbp https://go.microsoft.com/fwlink/?LinkID=2096498
Disconnect-PSSession dnsn https://go.microsoft.com/fwlink/?LinkID=2096576
Enable-PSBreakpoint ebp https://go.microsoft.com/fwlink/?LinkID=2096700
Enter-PSSession etsn https://go.microsoft.com/fwlink/?LinkID=2096695
Exit-PSSession exsn https://go.microsoft.com/fwlink/?LinkID=2096787
Export-Alias epal https://go.microsoft.com/fwlink/?LinkID=2096597
Export-Csv epcsv https://go.microsoft.com/fwlink/?LinkID=2096608
ForEach-Object % https://go.microsoft.com/fwlink/?LinkID=2096867
ForEach-Object foreach https://go.microsoft.com/fwlink/?LinkID=2096867
Format-Custom fc https://go.microsoft.com/fwlink/?LinkID=2096929
Format-Hex fhx https://go.microsoft.com/fwlink/?LinkId=2096611
Format-List fl https://go.microsoft.com/fwlink/?LinkID=2096928
Format-Table ft https://go.microsoft.com/fwlink/?LinkID=2096703
Format-Wide fw https://go.microsoft.com/fwlink/?LinkID=2096930
Get-Alias gal https://go.microsoft.com/fwlink/?LinkID=2096702
Get-ChildItem dir
Get-ChildItem gci
Get-ChildItem ls
Get-Command gcm https://go.microsoft.com/fwlink/?LinkID=2096579
Get-Content cat
Get-Content gc
Get-Content type
Get-Error gerr https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/get-error
Get-History ghy https://go.microsoft.com/fwlink/?LinkID=2096788
Get-History h https://go.microsoft.com/fwlink/?LinkID=2096788
Get-History history https://go.microsoft.com/fwlink/?LinkID=2096788
Get-Item gi
Get-ItemProperty gp
Get-ItemPropertyValue gpv
Get-Job gjb https://go.microsoft.com/fwlink/?LinkID=2096582
Get-Location gl
Get-Location pwd
Get-Member gm https://go.microsoft.com/fwlink/?LinkID=2096704
Get-Module gmo https://go.microsoft.com/fwlink/?LinkID=2096696
Get-Process gps
Get-Process ps
Get-PSBreakpoint gbp https://go.microsoft.com/fwlink/?LinkID=2097108
Get-PSCallStack gcs https://go.microsoft.com/fwlink/?LinkID=2096705
Get-PSDrive gdr
Get-PSSession gsn https://go.microsoft.com/fwlink/?LinkID=2096697
Get-Service gsv
Get-Unique gu https://go.microsoft.com/fwlink/?LinkID=2097028
Get-Variable gv https://go.microsoft.com/fwlink/?LinkID=2096711
Group-Object group https://go.microsoft.com/fwlink/?LinkID=2096619
help man https://go.microsoft.com/fwlink/?LinkID=113316
Import-Alias ipal https://go.microsoft.com/fwlink/?LinkID=2097125
Import-Csv ipcsv https://go.microsoft.com/fwlink/?LinkID=2097020
Import-Module ipmo https://go.microsoft.com/fwlink/?LinkID=2096585
Invoke-Command icm https://go.microsoft.com/fwlink/?LinkID=2096789
Invoke-Expression iex https://go.microsoft.com/fwlink/?LinkID=2097030
Invoke-History ihy https://go.microsoft.com/fwlink/?LinkID=2096586
Invoke-History r https://go.microsoft.com/fwlink/?LinkID=2096586
Invoke-Item ii
Invoke-RestMethod irm https://go.microsoft.com/fwlink/?LinkID=2096706
Invoke-WebRequest iwr https://go.microsoft.com/fwlink/?LinkID=2097126
Measure-Object measure https://go.microsoft.com/fwlink/?LinkID=2096617
mkdir md
Move-Item mi
Move-Item move
Move-Item mv
Move-ItemProperty mp
New-Alias nal https://go.microsoft.com/fwlink/?LinkID=2097022
New-Item ni
New-Module nmo https://go.microsoft.com/fwlink/?LinkID=2096698
New-PSDrive mount
New-PSDrive ndr
New-PSSession nsn https://go.microsoft.com/fwlink/?LinkID=2096484
New-Variable nv https://go.microsoft.com/fwlink/?LinkID=2097121
Out-GridView ogv https://go.microsoft.com/fwlink/?LinkID=2109378
Out-Host oh https://go.microsoft.com/fwlink/?LinkID=2096863
Pop-Location popd
Push-Location pushd
Receive-Job rcjb https://go.microsoft.com/fwlink/?LinkID=2096965
Receive-PSSession rcsn https://go.microsoft.com/fwlink/?LinkID=2096800
Remove-Item del
Remove-Item erase
Remove-Item rd
Remove-Item ri
Remove-Item rm
Remove-Item rmdir
Remove-ItemProperty rp
Remove-Job rjb https://go.microsoft.com/fwlink/?LinkID=2096868
Remove-Module rmo https://go.microsoft.com/fwlink/?LinkID=2096802
Remove-PSBreakpoint rbp https://go.microsoft.com/fwlink/?LinkID=2097134
Remove-PSDrive rdr
Remove-PSSession rsn https://go.microsoft.com/fwlink/?LinkID=2096963
Remove-Variable rv https://go.microsoft.com/fwlink/?LinkID=2097123
Rename-Item ren
Rename-Item rni
Rename-ItemProperty rnp
Resolve-Path rvpa
Select-Object select https://go.microsoft.com/fwlink/?LinkID=2096716
Select-String sls https://go.microsoft.com/fwlink/?LinkID=2097119
Set-Alias sal https://go.microsoft.com/fwlink/?LinkID=2096625
Set-Item si
Set-ItemProperty sp
Set-Location cd
Set-Location chdir
Set-Location sl
Set-PSBreakpoint sbp https://go.microsoft.com/fwlink/?LinkID=2096623
Set-Variable set https://go.microsoft.com/fwlink/?LinkID=2096624
Set-Variable sv https://go.microsoft.com/fwlink/?LinkID=2096624
Show-Command shcm https://go.microsoft.com/fwlink/?LinkID=2109589
Sort-Object sort https://go.microsoft.com/fwlink/?LinkID=2097038
Start-Job sajb https://go.microsoft.com/fwlink/?LinkID=2096796
Start-Process saps
Start-Process start
Start-Service sasv
Start-Sleep sleep https://go.microsoft.com/fwlink/?LinkID=2097041
Stop-Job spjb https://go.microsoft.com/fwlink/?LinkID=2096795
Stop-Process kill
Stop-Process spps
Stop-Service spsv
Tee-Object tee https://go.microsoft.com/fwlink/?LinkID=2097034
Wait-Job wjb https://go.microsoft.com/fwlink/?LinkID=2096902
Where-Object ? https://go.microsoft.com/fwlink/?LinkID=2096806
Where-Object where https://go.microsoft.com/fwlink/?LinkID=2096806
Write-Output echo https://go.microsoft.com/fwlink/?LinkID=2097117
Write-Output write https://go.microsoft.com/fwlink/?LinkID=2097117
参考情報:すべての項目を表示(一部省略) < クリックで折りたたみが開く >
HelpUri ResolvedCommandName DisplayName ReferencedCommand ResolvedCommand Definition Options Description OutputType Name CommandType Source Version Visibility ModuleName Module RemotingCapability Parameters ParameterSets
https://go.microsoft.com/fwlink/?LinkID=2096806 Where-Object ? -> Where-Object Where-Object Where-Object Where-Object ReadOnly, AllScope System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] ? Alias Public None System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
https://go.microsoft.com/fwlink/?LinkID=2096867 ForEach-Object % -> ForEach-Object ForEach-Object ForEach-Object ForEach-Object ReadOnly, AllScope System.Collections.ObjectModel.ReadOnlyCollection`1[System.Management.Automation.PSTypeName] % Alias Public None System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata]
ac -> Add-Content Add-Content ReadOnly ac Alias Public PowerShell
cat -> Get-Content Get-Content None cat Alias Public PowerShell
cd -> Set-Location Set-Location AllScope cd Alias Public PowerShell
~~~ 以降は省略 ~~~

自分用のメモ:コマンド結果をMarkdownの表に変換した方法

コマンド結果をMarkdownの表に変換した方法 < クリックで折りたたみが開く >
  1. PowerShellコマンド結果をCSVファイルに出力
    • PowerShell 5.1で実行したコマンド
      Get-Alias | Export-Csv -NoTypeInformation D:\Downloads\PS5.1_alias.csv -Encoding UTF8
    • PowerShell 7.3.6で実行したコマンド
      Get-Alias | Export-Csv D:\Downloads\PS7.3_alias.csv -Encoding UTF8
  2. CSVファイルからExcelファイルに変換
    カンマ(,)区切りからタブ(\t)区切りにする為、Excelファイルに変換する。
    https://command-lab.com/tech/csv-excel/
  3. Excelファイルの表をコピーしテキストエディターに貼り付け
    Excel内にあるコマンド結果の表がタブ区切りのテキスト形式となる。
    * 私は正規表現が可能なテキストエディターとしてVS Codeを使用しました。
  4. テキストエディターの正規表現を使いMarkdown形式に変換
    1. Ctrl + H で置換機能を起動
    2. 置換機能のオプションで正規表現を使用するをON
    3. 下記条件で置換
      • 検索条件
        ^(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)$
      • 置換文字
        | $1 | $2 | $3 | $4 | $5 | $6 | $7 | $8 | $9 | $10 | $11 | $12 | $13 | $14 | $15 | $16 | $17 | $18 | $19 |
  5. Markdownのテーブル形式のテキストデータが完成

PowerShell 5.1 と 7.3.6 の差異を比較

差異があるコマンドレットだけをピックアップしました。

差異の内容 PowerShellコマンドレット エイリアス名
5.1のみ Add-PSSnapIn asnp
5.1のみ ConvertFrom-String CFS
5.1のみ Export-PSSession epsn
7.3のみ Get-Error gerr
5.1のみ Get-PSSnapIn gsnp
5.1のみ Get-WmiObject gwmi
5.1のみ Import-PSSession ipsn
5.1のみ Invoke-WebRequest curl
5.1のみ Invoke-WebRequest wget
5.1のみ New-PSSessionConfigurationFile npssc
5.1のみ Out-Printer lp
5.1のみ powershell_ise.exe ise
5.1のみ Remove-PSSnapin rsnp
5.1のみ Remove-WMIObject rwmi
5.1のみ Resume-Job rujb
5.1のみ Set-Content sc
5.1のみ Set-WMIInstance swmi
5.1のみ Suspend-Job sujb
5.1のみ Trace-Command trcm
PowerShellバージョン毎のエイリアス対応 < クリックで折りたたみが開く >
5.1 7.3 PowerShellコマンドレット エイリアス名
Add-Content ac
Add-PSSnapIn asnp
Clear-Content clc
Clear-History clhy
Clear-Host clear
Clear-Host cls
Clear-Item cli
Clear-ItemProperty clp
Clear-Variable clv
Compare-Object compare
Compare-Object diff
Connect-PSSession cnsn
ConvertFrom-String CFS
Convert-Path cvpa
Copy-Item copy
Copy-Item cp
Copy-Item cpi
Copy-ItemProperty cpp
Disable-PSBreakpoint dbp
Disconnect-PSSession dnsn
Enable-PSBreakpoint ebp
Enter-PSSession etsn
Exit-PSSession exsn
Export-Alias epal
Export-Csv epcsv
Export-PSSession epsn
ForEach-Object %
ForEach-Object foreach
Format-Custom fc
Format-Hex fhx
Format-List fl
Format-Table ft
Format-Wide fw
Get-Alias gal
Get-ChildItem dir
Get-ChildItem gci
Get-ChildItem ls
Get-Command gcm
Get-Content cat
Get-Content gc
Get-Content type
Get-Error gerr
Get-History ghy
Get-History h
Get-History history
Get-Item gi
Get-ItemProperty gp
Get-ItemPropertyValue gpv
Get-Job gjb
Get-Location gl
Get-Location pwd
Get-Member gm
Get-Module gmo
Get-Process gps
Get-Process ps
Get-PSBreakpoint gbp
Get-PSCallStack gcs
Get-PSDrive gdr
Get-PSSession gsn
Get-PSSnapIn gsnp
Get-Service gsv
Get-Unique gu
Get-Variable gv
Get-WmiObject gwmi
Group-Object group
help man
Import-Alias ipal
Import-Csv ipcsv
Import-Module ipmo
Import-PSSession ipsn
Invoke-Command icm
Invoke-Expression iex
Invoke-History ihy
Invoke-History r
Invoke-Item ii
Invoke-RestMethod irm
Invoke-WebRequest curl
Invoke-WebRequest iwr
Invoke-WebRequest wget
Invoke-WMIMethod iwmi
Measure-Object measure
mkdir md
Move-Item mi
Move-Item move
Move-Item mv
Move-ItemProperty mp
New-Alias nal
New-Item ni
New-Module nmo
New-PSDrive mount
New-PSDrive ndr
New-PSSession nsn
New-PSSessionConfigurationFile npssc
New-Variable nv
Out-GridView ogv
Out-Host oh
Out-Printer lp
Pop-Location popd
powershell_ise.exe ise
Push-Location pushd
Receive-Job rcjb
Receive-PSSession rcsn
Remove-Item del
Remove-Item erase
Remove-Item rd
Remove-Item ri
Remove-Item rm
Remove-Item rmdir
Remove-ItemProperty rp
Remove-Job rjb
Remove-Module rmo
Remove-PSBreakpoint rbp
Remove-PSDrive rdr
Remove-PSSession rsn
Remove-PSSnapin rsnp
Remove-Variable rv
Remove-WMIObject rwmi
Rename-Item ren
Rename-Item rni
Rename-ItemProperty rnp
Resolve-Path rvpa
Resume-Job rujb
Select-Object select
Select-String sls
Set-Alias sal
Set-Content sc
Set-Item si
Set-ItemProperty sp
Set-Location cd
Set-Location chdir
Set-Location sl
Set-PSBreakpoint sbp
Set-Variable set
Set-Variable sv
Set-WMIInstance swmi
Show-Command shcm
Sort-Object sort
Start-Job sajb
Start-Process saps
Start-Process start
Start-Service sasv
Start-Sleep sleep
Stop-Job spjb
Stop-Process kill
Stop-Process spps
Stop-Service spsv
Suspend-Job sujb
Tee-Object tee
Trace-Command trcm
Wait-Job wjb
Where-Object ?
Where-Object where
Write-Output echo
Write-Output write

公式リファレンス「Get-Aliasコマンド」

https://learn.microsoft.com/ja-jp/powershell/module/microsoft.powershell.utility/get-alias

まとめ

エイリアスを取得できるPowerShellのコマンドレット「Get-Alias」の結果を、
5.1 と v7.3.6 の2つのバージョンで確認しました。

PowerShellのエイリアスを使う用途としては、CLIでコマンドレットを打つときに時短となり便利そうですね。
エイリアスの内容を、ざっと見る限りUNIXのコマンドを流用しているようなので、
UNIXやLinuxのコマンドをご存じの方は、作業効率が上がりそうです。
ただ、エイリアスはコマンドのみでオプションに関してはPowerShellコマンドレットの物を使用する必要がありますので、ご注意ください。

また、PowerShellスクリプトを作成する際、エイリアスを使ってしまうとPowerShellのコマンドレットなのか、
OSのコマンド(Windows OSであればコマンドプロンプト)なのかが不明確になってしまいます。
PowerShellスクリプト作成時は、省略していないフルのコマンドレットでコードを書いた方が可読性が良さそうです。

関連記事

https://haretokidoki-blog.com/pasocon_powershell-startup/
https://zenn.dev/haretokidoki/articles/7e6924ff0cc960

GitHubで編集を提案

Discussion