HOME > > >

自動変数

自動変数はPowerShellによって作成される変数でReadオンリー

自動変数一覧

設定される自動変数を確認するには下記コマンドをうつ。

  1. > Get-Help about_Automatic_Variables

$$

最後に実行したコマンド

$?

最後に実行したコマンドの結果。TRUEまたはFALSEが設定される。

  1. > $?
  2. True

$^

最後に実行したコマンドの最初のコマンド

  1. > Get-Process | Sort-Object CPU -Descending | Select-Object -First 11
  2.  
  3. Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
  4. -------  ------    -----      -----     ------     --  -- -----------
  5. 904      65  1048800     672900   1,504.89  12324   1 phpstorm64
  6. 3010     160   185676     130168     844.19  11180   1 Dropbox
  7. 3271      96   165984     200920     440.89  11424   1 chrome
  8. 782      49   136592     132232     414.34  12440   1 chrome
  9. 2801      83    73204     125252     359.34   1440   1 explorer
  10. 569      33    30652      46148     146.77   5264   1 chrome
  11. 2232      93   284552      93956      89.38   7984   1 powershell
  12. 524      17     7356      19848      70.38   6616   1 SynTPEnh
  13. 1044     121   163096      68480      48.97  11708   1 Adobe Desktop Service
  14. 702      29    18044       6128      46.02   9124   1 SettingSyncHost
  15. 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のインストールディレクトリを取得する

  1. > $PSHOME
  2. C:\Windows\System32\WindowsPowerShell\v1.0

$PSItem

$PSScriptRoot

$PSSenderInfo

$PsUICulture

$PsVersionTable

PowerShellのバージョン情報を取得する。

  1. > $PSVersionTable
  2.  
  3. Name                           Value
  4. ----                           -----
  5. PSVersion                      5.1.17134.590
  6. PSEdition                      Desktop
  7. PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
  8. BuildVersion                   10.0.17134.590
  9. CLRVersion                     4.0.30319.42000
  10. WSManStackVersion              3.0
  11. PSRemotingProtocolVersion      2.3
  12. SerializationVersion           1.1.0.1

$Pwd

カレントディレクトリのフルパスが定義されたSystem.Management.Automation.PathInfo

  1. > $PWD
  2.  
  3. Path
  4. ----
  5. C:\Users\test_user
  6.  
  7. > $PWD | Get-Member
  8.  
  9.    TypeName: System.Management.Automation.PathInfo
  10.  
  11. Name         MemberType Definition
  12. ----         ---------- ----------
  13. Equals       Method     bool Equals(System.Object obj)
  14. GetHashCode  Method     int GetHashCode()
  15. GetType      Method     type GetType()
  16. ToString     Method     string ToString()
  17. Drive        Property   System.Management.Automation.PSDriveInfo Drive {get;}
  18. Path         Property   string Path {get;}
  19. Provider     Property   System.Management.Automation.ProviderInfo Provider {get;}
  20. ProviderPath Property   string ProviderPath {get;}

$ReportErrorShowExceptionClass

$ReportErrorShowInnerException

$ReportErrorShowSource

$ReportErrorShowStackTrace

$Sender

$ShellID

現在のシェルの識別子

PowerShellのインストールディレクトリを取得する

  1. > $ShellId
  2. Microsoft.PowerShell

$StackTrace

$This

$True

TRUE