PSScriptRoot is null: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
(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, $…“)
(kein Unterschied)

Version vom 16. August 2021, 10:07 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 ($GLOBAL:psISE) {
     Split-Path -Path $GLOBAL:psISE.CurrentFile.FullPath        
} else {
     $GLOBAL:PSScriptRoot
}