The PSScriptRoot variable appears to have a value, but it cannot be used. My apologies if this turns out to be silly. What's going on?
PS C:\> Get-ChildItem Variable:PSScriptRoot
Name Value
---- -----
PSScriptRoot C:\Windows\System32\WindowsPowerShell\v1.0
PS C:\> $PSScriptRoot
PS C:\> $PSScriptRoot.Length
0
PS C:\> $PSScriptRoot.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS C:\> $PSScriptRoot | Format-List * -Force
Length : 0
PS C:\> $null -eq $PSScriptRoot
False
PS C:\> "===$PSScriptRoot==="
======
PS C:\> $PSVersionTable.PSVersion.ToString()
5.1.17763.1490
$PSScriptRootwill only work if the script is saved and you're executing the whole script (not a portion of the code). Hopefully it makes sense.