PSScriptRoot is null
Aus Wiki-WebPerfect
Version vom 16. August 2021, 09:07 Uhr von Admin (Diskussion | Beiträge)
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 }