自動変数はPowerShellによって作成される変数でReadオンリー
自動変数一覧
設定される自動変数を確認するには下記コマンドをうつ。
> Get-Help about_Automatic_Variables
$$
最後に実行したコマンド
$?
最後に実行したコマンドの結果。TRUEまたはFALSEが設定される。
$^
最後に実行したコマンドの最初のコマンド
> Get-Process | Sort-Object CPU -Descending | Select-Object -First 11
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
904 65 1048800 672900 1,504.89 12324 1 phpstorm64
3010 160 185676 130168 844.19 11180 1 Dropbox
3271 96 165984 200920 440.89 11424 1 chrome
782 49 136592 132232 414.34 12440 1 chrome
2801 83 73204 125252 359.34 1440 1 explorer
569 33 30652 46148 146.77 5264 1 chrome
2232 93 284552 93956 89.38 7984 1 powershell
524 17 7356 19848 70.38 6616 1 SynTPEnh
1044 121 163096 68480 48.97 11708 1 Adobe Desktop Service
702 29 18044 6128 46.02 9124 1 SettingSyncHost
379 34 89928 121788 44.73 16408 1 chrome
$_
$PSItemと同様。
$AllNodes
$Args
$ConsoleFileName
$Error
$Event
$EventArgs
$EventSubscriber
$ExecutionContext
$False
$ForEach
$Home
$Host
$Input
$LastExitCode
$Matches
$MyInvocation
$NestedPromptLevel
$NULL
$OFS
$PID
$Profile
プロファイルのパス
$PSBoundParameters
$PsCmdlet
$PSCommandPath
$PsCulture
$PSDebugContext
$PSHOME
PowerShellのインストールディレクトリを取得する
> $PSHOME
C:\Windows\System32\WindowsPowerShell\v1.0
$PSItem
$PSScriptRoot
$PSSenderInfo
$PsUICulture
$PsVersionTable
PowerShellのバージョン情報を取得する。
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.590
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.590
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
$Pwd
カレントディレクトリのフルパスが定義されたSystem.Management.Automation.PathInfo
> $PWD
Path
----
C:\Users\test_user
> $PWD | Get-Member
TypeName: System.Management.Automation.PathInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Drive Property System.Management.Automation.PSDriveInfo Drive {get;}
Path Property string Path {get;}
Provider Property System.Management.Automation.ProviderInfo Provider {get;}
ProviderPath Property string ProviderPath {get;}
$ReportErrorShowExceptionClass
$ReportErrorShowInnerException
$ReportErrorShowSource
$ReportErrorShowStackTrace
$Sender
$ShellID
現在のシェルの識別子
PowerShellのインストールディレクトリを取得する
> $ShellId
Microsoft.PowerShell
$StackTrace
$This
$True
TRUE