Search

PSScriptRoot in ps1 script in PSv3 is empty in ISE by J Stangroome

Active

3
0
Sign in
to vote
Type: Bug
ID: 769359
Opened: 10/31/2012 1:56:02 PM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
In the PSv3 documentation, $PSScriptRoot is now an automatic variable that is populated for both modules and ps1 scripts. It works from PowerShell.exe but not from the ISE
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

I don't know if this issue existed previously
Reproduction Steps
1. Create a new script (eg c:\test.ps1) with the contents: gv PSScriptRoot
2. From PowerShell.exe, execute the script and see PSScriptRoot has a value.
3. From the ISE Console pane, execute the script and see PSScriptRoot had a value.
4. Open the script file in the ISE Script Pane and press F5 to run the script and see PSScriptRoot is blank.
Expected Results
The $PSScriptRoot automatic variable should have a value when run via F5 in the ISE.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Michael Naumov on 10/31/2012 at 4:32 PM
Interesting bug.

I could reproduce it

However even in that situation

$myVar = $PSScriptRoot

works as expected and the correct value is set to $myVar

Sign in to post a workaround.