PSScriptRoot is null: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Error == '''There is no error message, but $PSScriptRoot is empty/null.''' == Cause == ''This occurs because you are using ISE and when ISE is launched, $…“) |
Admin (Diskussion | Beiträge) |
||
Zeile 10: | Zeile 10: | ||
*If you want to get the path in either shell or ISE you could use something like this: | *If you want to get the path in either shell or ISE you could use something like this: | ||
<source lang="powershell"> | <source lang="powershell"> | ||
− | If ($ | + | If ($SCRIPT:psISE) { |
− | Split-Path -Path $ | + | Split-Path -Path $SCRIPT:psISE.CurrentFile.FullPath |
} else { | } else { | ||
− | $ | + | $SCRIPT:PSScriptRoot |
} | } | ||
</source> | </source> |
Aktuelle Version vom 16. August 2021, 09:29 Uhr
Error
There is no error message, but $PSScriptRoot is empty/null.
Cause
This occurs because you are using ISE and when ISE is launched, $psISE is created and can be used to determine the current path of the ISE instance. This was introduced in version 3.0.
Solution
- If you want to get the path in either shell or ISE you could use something like this:
If ($SCRIPT:psISE) { Split-Path -Path $SCRIPT:psISE.CurrentFile.FullPath } else { $SCRIPT:PSScriptRoot }