PowerShell: コマンドレットや型のエイリアスを表示する

PowerShellで使用できるエイリアス(別名)には大きく2種類あります。 「コマンドレットのエイリアス」と 「型のエイリアス(型エイリアス)」です。

【エイリアス 2種類】
  • コマンドレットのエイリアス
  • 型のエイリアス

エイリアスを知っておくとPowerShellスクリプトの記述が短く済んで便利です。 特に型名は長いのがあるのでエイリアスは重宝します。 例えば正規表現で使うクラスで 「System.Text.RegularExpressions.Regex」のエイリアスは「regex」です。 このような場合はエイリアスを使った方が賢明です。

ここでは2つのエイリアスを表示する方法を紹介します。 先に結論を紹介しておきます。

コマンドレットのエイリアス
Get-Alias
型のエイリアス
# 1行の場合
[PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get.GetEnumerator() | Sort-Object Key

# 2行に分ける場合
$s = "System.Management.Automation.TypeAccelerators"

[PSObject].Assembly.GetType($s)::Get.GetEnumerator() | Sort-Object Key

コマンドレットのエイリアス

PowerShellのコマンドレットのエイリアスを表示するには、 シンプルに「Get-Alias」コマンドレットを実行するだけです。 「Get-Alias」コマンドレットのエイリアスとして「alias」と 記述しても同じ結果を取得できます。

Get-Alias
実行例
PS D:\test\powershell> Get-Alias


CommandType     Name                     
                                        
-----------     ----                    
Alias           ? -> Where-Object       
Alias           % -> ForEach-Object
Alias           ac -> Add-Content
Alias           cat -> Get-Content
Alias           cd -> Set-Location
Alias           chdir -> Set-Location
Alias           clc -> Clear-Content
Alias           clear -> Clear-Host
Alias           clhy -> Clear-History
Alias           cli -> Clear-Item
Alias           clp -> Clear-ItemProperty
Alias           cls -> Clear-Host
Alias           clv -> Clear-Variable
Alias           cnsn -> Connect-PSSession
Alias           compare -> Compare-Object
Alias           copy -> Copy-Item
Alias           cp -> Copy-Item
Alias           cpi -> Copy-Item
Alias           cpp -> Copy-ItemProperty
Alias           cvpa -> Convert-Path
Alias           dbp -> Disable-PSBreakpoint
Alias           del -> Remove-Item
Alias           diff -> Compare-Object
Alias           dir -> Get-ChildItem
Alias           dnsn -> Disconnect-PSSession
Alias           ebp -> Enable-PSBreakpoint
Alias           echo -> Write-Output
Alias           epal -> Export-Alias
Alias           epcsv -> Export-Csv
Alias           erase -> Remove-Item
Alias           etsn -> Enter-PSSession
Alias           exsn -> Exit-PSSession
Alias           fc -> Format-Custom
Alias           fhx -> Format-Hex       
Alias           fl -> Format-List
Alias           foreach -> ForEach-Object
Alias           ft -> Format-Table
Alias           fw -> Format-Wide
Alias           gal -> Get-Alias
Alias           gbp -> Get-PSBreakpoint
Alias           gc -> Get-Content
Alias           gcb -> Get-Clipboard 
Alias           gci -> Get-ChildItem
Alias           gcm -> Get-Command
Alias           gcs -> Get-PSCallStack
Alias           gdr -> Get-PSDrive
Alias           gerr -> Get-Error
Alias           ghy -> Get-History
Alias           gi -> Get-Item
Alias           gin -> Get-ComputerInfo 
Alias           gjb -> Get-Job
Alias           gl -> Get-Location
Alias           gm -> Get-Member
Alias           gmo -> Get-Module
Alias           gp -> Get-ItemProperty
Alias           gps -> Get-Process
Alias           gpv -> Get-ItemPropertyValue
Alias           group -> Group-Object
Alias           gsn -> Get-PSSession
Alias           gsv -> Get-Service
Alias           gtz -> Get-TimeZone 
Alias           gu -> Get-Unique
Alias           gv -> Get-Variable
Alias           h -> Get-History
Alias           history -> Get-History
Alias           icm -> Invoke-Command
Alias           iex -> Invoke-Expression
Alias           ihy -> Invoke-History
Alias           ii -> Invoke-Item
Alias           ipal -> Import-Alias
Alias           ipcsv -> Import-Csv
Alias           ipmo -> Import-Module
Alias           irm -> Invoke-RestMethod
Alias           iwr -> Invoke-WebRequest
Alias           kill -> Stop-Process
Alias           ls -> Get-ChildItem
Alias           man -> help
Alias           md -> mkdir
Alias           measure -> Measure-Object
Alias           mi -> Move-Item
Alias           mount -> New-PSDrive
Alias           move -> Move-Item
Alias           mp -> Move-ItemProperty
Alias           mv -> Move-Item
Alias           nal -> New-Alias
Alias           ndr -> New-PSDrive
Alias           ni -> New-Item
Alias           nmo -> New-Module
Alias           nsn -> New-PSSession
Alias           nv -> New-Variable
Alias           ogv -> Out-GridView
Alias           oh -> Out-Host
Alias           popd -> Pop-Location
Alias           ps -> Get-Process
Alias           psedit -> Open-EditorFile
Alias           pushd -> Push-Location
Alias           pwd -> Get-Location
Alias           r -> Invoke-History
Alias           rbp -> Remove-PSBreakpoint
Alias           rcjb -> Receive-Job
Alias           rcsn -> Receive-PSSession
Alias           rd -> Remove-Item
Alias           rdr -> Remove-PSDrive
Alias           ren -> Rename-Item
Alias           ri -> Remove-Item
Alias           rjb -> Remove-Job
Alias           rm -> Remove-Item
Alias           rmdir -> Remove-Item
Alias           rmo -> Remove-Module
Alias           rni -> Rename-Item
Alias           rnp -> Rename-ItemProperty
Alias           rp -> Remove-ItemProperty
Alias           rsn -> Remove-PSSession
Alias           rv -> Remove-Variable
Alias           rvpa -> Resolve-Path
Alias           sajb -> Start-Job
Alias           sal -> Set-Alias
Alias           saps -> Start-Process
Alias           sasv -> Start-Service
Alias           sbp -> Set-PSBreakpoint
Alias           scb -> Set-Clipboard    
Alias           select -> Select-Object
Alias           set -> Set-Variable
Alias           shcm -> Show-Command
Alias           si -> Set-Item
Alias           sl -> Set-Location
Alias           sleep -> Start-Sleep
Alias           sls -> Select-String
Alias           sort -> Sort-Object
Alias           sp -> Set-ItemProperty
Alias           spjb -> Stop-Job
Alias           spps -> Stop-Process
Alias           spsv -> Stop-Service
Alias           start -> Start-Process
Alias           stz -> Set-TimeZone  
Alias           sv -> Set-Variable
Alias           tee -> Tee-Object
Alias           type -> Get-Content
Alias           where -> Where-Object
Alias           wjb -> Wait-Job
Alias           write -> Write-Output

型のエイリアス(型エイリアス)

型エイリアスを取得する場合、 専用のコマンドレットが無いので少し複雑になります。
下のコードは1行で記述する場合と、2行に分けて記述する場合の2通りを紹介しています。 どちらでもやりやすい方で実行してください。

# 1行の場合
[PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get.GetEnumerator() | Sort-Object Key

# 2行に分ける場合
$s = "System.Management.Automation.TypeAccelerators"

[PSObject].Assembly.GetType($s)::Get.GetEnumerator() | Sort-Object Key
実行例
PS D:\test\powershell> $s = "System.Management.Automation.TypeAccelerators"

PS D:\test\powershell> [PSObject].Assembly.GetType($s)::Get.GetEnumerator() | Sort-Object Key

Key                          Value
---                          -----
adsi                         System.DirectoryServices.DirectoryEntry
adsisearcher                 System.DirectoryServices.DirectorySearcher
Alias                        System.Management.Automation.AliasAttribute
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute
AllowNull                    System.Management.Automation.AllowNullAttribute
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute
array                        System.Array
bigint                       System.Numerics.BigInteger
bool                         System.Boolean
byte                         System.Byte
char                         System.Char
cimclass                     Microsoft.Management.Infrastructure.CimClass
cimconverter                 Microsoft.Management.Infrastructure.CimConverter
ciminstance                  Microsoft.Management.Infrastructure.CimInstance
CimSession                   Microsoft.Management.Infrastructure.CimSession
cimtype                      Microsoft.Management.Infrastructure.CimType
CmdletBinding                System.Management.Automation.CmdletBindingAttribute
cultureinfo                  System.Globalization.CultureInfo
datetime                     System.DateTime
decimal                      System.Decimal
double                       System.Double
DscLocalConfigurationManager System.Management.Automation.DscLocalConfigurationManagerAttribute
DscProperty                  System.Management.Automation.DscPropertyAttribute
DscResource                  System.Management.Automation.DscResourceAttribute
float                        System.Single
guid                         System.Guid
hashtable                    System.Collections.Hashtable
initialsessionstate          System.Management.Automation.Runspaces.InitialSessionState
int                          System.Int32
int16                        System.Int16
int32                        System.Int32
int64                        System.Int64
ipaddress                    System.Net.IPAddress
IPEndpoint                   System.Net.IPEndPoint
long                         System.Int64
mailaddress                  System.Net.Mail.MailAddress
NullString                   System.Management.Automation.Language.NullString
ObjectSecurity               System.Security.AccessControl.ObjectSecurity
OutputType                   System.Management.Automation.OutputTypeAttribute
Parameter                    System.Management.Automation.ParameterAttribute
PhysicalAddress              System.Net.NetworkInformation.PhysicalAddress
powershell                   System.Management.Automation.PowerShell
psaliasproperty              System.Management.Automation.PSAliasProperty
pscredential                 System.Management.Automation.PSCredential
pscustomobject               System.Management.Automation.PSObject
PSDefaultValue               System.Management.Automation.PSDefaultValueAttribute
pslistmodifier               System.Management.Automation.PSListModifier
psmoduleinfo                 System.Management.Automation.PSModuleInfo
psnoteproperty               System.Management.Automation.PSNoteProperty
psobject                     System.Management.Automation.PSObject
psprimitivedictionary        System.Management.Automation.PSPrimitiveDictionary
psscriptmethod               System.Management.Automation.PSScriptMethod
psscriptproperty             System.Management.Automation.PSScriptProperty
PSTypeNameAttribute          System.Management.Automation.PSTypeNameAttribute
psvariable                   System.Management.Automation.PSVariable
psvariableproperty           System.Management.Automation.PSVariableProperty
ref                          System.Management.Automation.PSReference
regex                        System.Text.RegularExpressions.Regex
runspace                     System.Management.Automation.Runspaces.Runspace
runspacefactory              System.Management.Automation.Runspaces.RunspaceFactory
sbyte                        System.SByte
scriptblock                  System.Management.Automation.ScriptBlock
securestring                 System.Security.SecureString
single                       System.Single
string                       System.String
SupportsWildcards            System.Management.Automation.SupportsWildcardsAttribute
switch                       System.Management.Automation.SwitchParameter
timespan                     System.TimeSpan
type                         System.Type
uint16                       System.UInt16
uint32                       System.UInt32
uint64                       System.UInt64
uri                          System.Uri
ValidateCount                System.Management.Automation.ValidateCountAttribute
ValidateDrive                System.Management.Automation.ValidateDriveAttribute
ValidateLength               System.Management.Automation.ValidateLengthAttribute
ValidateNotNull              System.Management.Automation.ValidateNotNullAttribute
ValidateNotNullOrEmpty       System.Management.Automation.ValidateNotNullOrEmptyAttribute
ValidatePattern              System.Management.Automation.ValidatePatternAttribute
ValidateRange                System.Management.Automation.ValidateRangeAttribute
ValidateScript               System.Management.Automation.ValidateScriptAttribute
ValidateSet                  System.Management.Automation.ValidateSetAttribute
ValidateTrustedData          System.Management.Automation.ValidateTrustedDataAttribute
ValidateUserDrive            System.Management.Automation.ValidateUserDriveAttribute
version                      System.Version
void                         System.Void
WildcardPattern              System.Management.Automation.WildcardPattern
wmi                          System.Management.ManagementObject
wmiclass                     System.Management.ManagementClass
wmisearcher                  System.Management.ManagementObjectSearcher
X500DistinguishedName        System.Security.Cryptography.X509Certificates.X500DistinguishedName
X509Certificate              System.Security.Cryptography.X509Certificates.X509Certificate
xml                          System.Xml.XmlDocument
PowerShell