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.