-1

While this Powershell PSScriptRoot is null (pasted below for an easy read) seems to answer the question it does not in my case.

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 PowerSehll console without a script file You marked only this expression for execution in PowerShell ISE

I am running the ps in a .ps1 file outside the ISE and still getting a null pointer.

paulhr
  • 339
  • 4
  • 17
  • 2
    `$PsScriptRoot` in PowerShell v2 work only inside `.psm1` script module files, but not inside `.ps1` ordinary script files. – user4003407 Aug 29 '17 at 17:16
  • Possible duplicate of [How can I get the file system location of a PowerShell script?](https://stackoverflow.com/questions/3667238/how-can-i-get-the-file-system-location-of-a-powershell-script) – BenH Aug 29 '17 at 17:32

1 Answers1

3

$PSScriptRoot is an automatic variable introduced in PowerShell v3.

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63