Skip to main content

Automatische Variablen

Variablen die von PowerShell je nach Kontext, selbst deklariert werden.

Variable Beschreibung
$Host Sie repräsentiert den Host, also das Programm, in dem PowerShell gerade läuft.
$PSCommandPath Vollständiger Pfad zum aktuellen Skript
$PSModulePath Beinhaltet die Pfade zu den Modulen
$PSScriptRoot Der Pfad zum Ordner worin sich das aktuelle Skript befindet
$MyInvocation Enthält Infos darüber, wie das Skript aufgerufen wurde
$PSCommandPath

$PSScriptRootPSCommandPath

 

  • Datentyp: System.String

$PSCommandPath

    Datentyp: System.String
    $PSScriptRoot

    $PSScriptRoot

    • Datentyp: System.String

    Der$PSScriptRoot Pfadist zumeine automatische Variable, die den Ordner worinenthält, sichin dem das aktuelle Skript befindet.bzw. Modul liegt.

    Beispiel:

    C:\Dev\FormBuilder\Modules\FormBuilder\FormBuilder.psm1

    Dann:

    $PSScriptRoot
    # C:\Dev\FormBuilder\Modules\FormBuilder


    $MyInvocation

    • Datentyp: InvocationInfo

    Enthält Infos darüber, wie das Skript aufgerufen wurde

    • $MyInvocation.MyCommand – Informationen und die Idendität des aktuellen Kommando-Objekts
    • $MyInvocation.MyCommand.CommandType
    • $MyInvocation.MyCommand.Path – Enthält den Pfad zum aktuellen Skript