Powershell: $PSScriptroot & $PSCommandPath return null value

Created on 6 Jun 2017  路  6Comments  路  Source: PowerShell/PowerShell

Somehow the two return nothing to me.
Does anyone face same issue?

Environment data

PS C:> $PSVersionTable

Name Value
---- -----
PSVersion 5.1.14393.1198
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1198
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Issue-Question Resolution-Answered

All 6 comments

$PSCommandroot is not an automatic variable - did you mean $PSCommandPath?

As for $PSScriptRoot: please add more diagnostic info to your post. I see the symptom in neither v5.1 nor in v6-beta.2.

I'm sorry. Yes. $PSCommandPath.
I tried on 3 laptops which updated to Windows 10 1607. All show same behavior.
It just returned nothing.

Thanks for updating; however, I still don't see your symptom, and I'm running the same version of Windows 10 - at least as reported by winver.exe.

What does Get-CimInstance Win32_OperatingSystem return?
How, exactly are you referencing these variables?

As long as you cannot provide something that is _reproducible_ by others, the mystery will probably remain unsolved.

I'm sorry, I think I figured it out. It should be my text problem. It didn't show up yesterday. But it return value today after I re-enter the code.

I'm glad to hear it. Please close this issue then.

Closed.

Was this page helpful?
0 / 5 - 0 ratings