PowerShell PSScriptRoot is null PowerShell PSScriptRoot is null powershell powershell

PowerShell PSScriptRoot is null


If using ISE use:

$psISE.CurrentFile.FullPath

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.

See ISE Object Model Hierarchy

If you wanted to get the path in either shell or ISE you could use something like this:

if ($psISE){    Split-Path -Path $psISE.CurrentFile.FullPath        }else{    $global:PSScriptRoot}


You have to make sure that this expression is in a saved .ps1 script.

This can happened in following cases:

  • You use this statement in PowerShell ISE console
  • You use this statement in PowerShell console without a script file
  • You marked only this expression for execution in PowerShell ISE