Please feel free to provide feedback or file bugs here.

PSScriptRoot in ps1 script in PSv3 is empty in ISE

Votes from Connect: 13

Original Date Submitted: 11/1/2012 3:56:26 AM

Description:
********Contact Information********
Handle: J Stangroome
Site Name: PowerShell
Feedback ID: 769359
***************************************

Frequency: Always Happens
Regression: I don't know if this issue existed previously

Problem Description:
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

Product Studio item created by Connect Synchronizer due to creation of feedback ID 769359 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=769359).

Repro 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.

Internal BugId: 3931

25 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    8 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • John White commented  ·   ·  Flag as inappropriate

        As Jeroen said, this isn't actually a bug, and I agree that it's correct that it works this way. Just execute the script entirely to make it work.

      • Jeroen Bakker commented  ·   ·  Flag as inappropriate

        I don't think this is a bug but expected behavior, $PSScriptroot is an automatic variable created when running a script.
        Using F8 runs a selection of one or more script lines. These script lines are treated as single line commands by powershell, similar to running them one by one in powershell.exe, not as part of a script. The PSScriptroot variable only exists when you are actually executing a script.

        It would still be a nice feature to have the PSScriptroot variable available when testing a script in ISE.

      • Stephane Lapointe commented  ·   ·  Flag as inappropriate

        Still have the problem in ISE of PS5 on Windows 10 Enterprise

        $PSVersionTable gives me:

        Name Value
        ---- -----
        PSVersion 5.0.10240.16384
        WSManStackVersion 3.0
        SerializationVersion 1.1.0.1
        CLRVersion 4.0.30319.42000
        BuildVersion 10.0.10240.16384
        PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
        PSRemotingProtocolVersion 2.3

      • Wolfgang Groß commented  ·   ·  Flag as inappropriate

        Bug still seems to be present in ISE of PS5.
        But hey... who want to debug with real environment settings :-)

      Feedback and Knowledge Base