# Automatische Variablen

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

<table border="1" id="bkmrk-variable-beschreibun" style="border-collapse: collapse; width: 100%; height: 300px;"><colgroup><col style="width: 19.1895%;"></col><col style="width: 80.8105%;"></col></colgroup><thead><tr style="height: 29.8px;"><td class="align-center" style="height: 29.8px;">**Variable**</td><td class="align-center" style="height: 29.8px; padding-left: 40px;">**Beschreibung**</td></tr></thead><tbody><tr><td class="align-center">`<span style="color: rgb(53, 152, 219);">$Host</span>`</td><td>Sie repräsentiert den **Host**, also das Programm, in dem PowerShell gerade läuft.</td></tr><tr style="height: 30.4667px;"><td class="align-center" style="height: 30.4667px;"><span style="color: rgb(53, 152, 219);">`$PSCommandPath`</span></td><td style="height: 30.4667px;">Vollständiger Pfad zum aktuellen Skript</td></tr><tr style="height: 30.4667px;"><td class="align-center" style="height: 30.4667px;"><span style="color: rgb(35, 111, 161);">`<span style="color: rgb(53, 152, 219);">$PSModulePath</span>`</span></td><td style="height: 30.4667px;">Beinhaltet die Pfade zu den Modulen</td></tr><tr><td class="align-center" style="height: 30.4667px;">`<span style="color: rgb(53, 152, 219);">$PSScriptRoot</span>`</td><td style="height: 30.4667px;">Der Pfad zum Ordner worin sich das aktuelle Skript befindet</td></tr><tr style="height: 29.8px;"><td class="align-center" style="height: 29.8px;">`<span style="color: rgb(53, 152, 219);">$MyInvocation</span>`</td><td style="height: 29.8px;">Enthält Infos darüber, wie das Skript aufgerufen wurde</td></tr></tbody></table>

<details id="bkmrk-%24pscommandpath-%24psco"><summary>$PSCommandPath</summary>

### <span style="color: rgb(53, 152, 219);">`$PSCommandPath`</span>

- **Datentyp:** <span style="color: rgb(185, 106, 217);">`System.String`</span>

</details><details id="bkmrk-%24psscriptroot-%24psscr"><summary>$PSScriptRoot</summary>

### <span style="color: rgb(53, 152, 219);">`$PSScriptRoot`</span>

- **Datentyp:** <span style="color: rgb(185, 106, 217);">`System.String`</span>

`$PSScriptRoot` ist eine **automatische Variable**, die den Ordner enthält, in dem das aktuelle Skript bzw. Modul liegt.

Beispiel:

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

Dann:

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


</details>### <span style="color: rgb(35, 111, 161);">`<span style="color: rgb(53, 152, 219);">$MyInvocation</span>`</span>

- **Datentyp:** <span style="color: rgb(251, 238, 184);">`<span style="color: rgb(185, 106, 217);">InvocationInfo</span>`</span>

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

- <span style="color: rgb(255, 255, 255);">`<span style="color: rgb(53, 152, 219);">$MyInvocation</span>.<span style="color: rgb(251, 238, 184);">MyCommand</span>` </span>– Informationen und die Idendität des aktuellen Kommando-Objekts 
    - <span style="color: rgb(255, 255, 255);">`<span style="color: rgb(53, 152, 219);">$MyInvocation</span>.<span style="color: rgb(251, 238, 184);">MyCommand.CommandType</span>`</span>
    - <span style="color: rgb(255, 255, 255);">`<span style="color: rgb(53, 152, 219);">$MyInvocation</span>.<span style="color: rgb(251, 238, 184);">MyCommand.Path</span>` </span>– Enthält den Pfad zum aktuellen Skript