Please feel free to provide feedback or file bugs here.

bug? PowerShell does not return to current working location

1 vote
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

    wst shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

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

        It's not a bug on powershell.

        When you do Get-Module -ListAvailable | %{ Get-Command $_.Name } , powershell load modules to know which commands are available.

        The module SQLPS, has a PSDrive mounted after loading.

        So use Push-Location, Pop-Location inside foreach.

      • wst commented  ·   ·  Flag as inappropriate

        I'm not sure if it is a bug, I guess so…
        Windows 10 Pro x64 v1803 build 17134.112
        PS version 5.1.17134.112
        If I start Windows PowerShell, I'm at:
        PS C:\Users\foo>
        I type this:
        cd .\Desktop\
        to get to:
        PS C:\Users\foo\Desktop>
        Now when I execute this piece of code:
        Get-Module -ListAvailable |
        foreach { gcm -Module $_.Name -CommandType cmdlet, function | select Name}
        it ends at
        PS SQLSERVER:\>
        instead of at the original working directory where the script started:
        PS C:\Users\foo\Desktop>

      Feedback and Knowledge Base