none
setting the working direcory for powershell RRS feed

  • Question

  • Ok ok, i'm a PS noob, I admit it.  In my defense, I am not a scripting noob (lots of python experience) nor a programming noob (lots of C++ experience).  And I know my question is simple and must have a simple answer.  So here it is:

    How do I set the working directory to be other than c:\windows\windows32?  (My system is Windows 7 32 bit).

    I would like to have powershell start with it's directory set to c:\scripts (which I have created) and have edited the desktop shortcut I created for powershell to put c:\scripts in the Start Up field.  No joy though - it still starts in c:\windows\system32.   Interestingly, I have done the same thing with powershell_ise and it does show c:\scripts as its working directory when i invoke it.

    Thanks for the help,

    bluewingedolive

    PS: I doubt it makes a difference but i have issued set_executionpolicy remotesigned.

    Sunday, October 17, 2010 4:18 PM

Answers

  • PowerShell v2.0 is installed in the v1.0 by design.

    ------------------------------------------------------------------

    As far as answering the original question, I'd suggest adding the following command to your PowerShell profile:

    Set-Location c:\scripts
    

    To Create a PowerShell Profile

    1. Create a folder in your Documents folder called WindowsPowerShell
    2. Create a file called profile.ps1 inside this folder
    3. Add any desired initialization commands to this file (see above) and save it
    4. Every time you launch PowerShell, the profile script will be executed

    More Information

    For more information about how PowerShell profiles work, see:

    Get-Help about_profiles
    

    Alternatively, visit this link: about_profiles

    Cheers


    Trevor Sullivan
    http://trevorsullivan.net
    Friday, October 29, 2010 7:51 AM
    Moderator

All replies

  • If you want to set the location in the current powershell session, use "pushd c:\scripts" or "set-location c:\scripts".

    If you want to make it permanent, right click the powershell icon -> properties, and set the "Start in" field to "c:\scripts"

     

    Sunday, October 17, 2010 5:11 PM
    Moderator
  • Thanks, but.... um... well....  As I mentioned above, I tried putting c:\scripts in the "Start in"  field of the shortcut and it didn't work.

    bwo

    Sunday, October 17, 2010 5:16 PM
  • What Windows version are you using?

    if XP or Vista: what powershell version?

    I tested it on windows 7, and it worked without any problems.

     

    Sunday, October 17, 2010 5:23 PM
    Moderator
  • My system is Windows 7 32 bit.  I dont see that PowerShell is telling me its version directly, but the powershell.exe is contained in  c:\windows\system32\windowspowershell\v1.0.  So I assume this is version 1.0 of PowerShell.

    bwo

    Sunday, October 17, 2010 5:48 PM
  • Windows 7 has powershell v2.

     

    since the "start in" option is not working, you can create a profile (My Documents\WindowsPowerShell\profile.ps1) with: set-location c:\temp

    Sunday, October 17, 2010 6:13 PM
    Moderator
  • Ahhh!  My W7 system was originally a Vista machine.  I bought the upgrade and moved it to Windows 7.  I'll download and install v2 and let you know what happens.

    bwo

    Sunday, October 17, 2010 6:22 PM
  • when you upgrade vista do w7, powershell v2 is installed. no need for you to download and install ps v2.
    Sunday, October 17, 2010 6:33 PM
    Moderator
  • It turns out that I do have version 2.0 of PS.  The directory its in is named v1.0, but I suspect that's an artifact of having Vista on the system originally.   Here's the version info:

    PS C:\Windows\system32> get-host

    Name             : ConsoleHost
    Version          : 2.0
    InstanceId       : 674d392a-6cd9-428d-a36c-12f201c493b0
    UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture   : en-US
    CurrentUICulture : en-US
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace

     

    And to make sure I'm right about get-host....

    PS C:\Windows\system32> get-help get-host

    NAME
        Get-Host

    SYNOPSIS
        Gets an object that represents the current host program. And, displays Windows PowerShell version and regional info
        rmation by default.

    Sooo... the mystery continues.

    bluewingedolive

    Sunday, October 17, 2010 8:03 PM
  • It's not a bug. It's a feature. For whatever reason PowerShell V2 is located in a folder named v1.0.
    Sunday, October 17, 2010 9:19 PM
  • *chuckles*  I've created "features" like that too.  But... that's not the original problem.  To recap:

    Others seem to be able to put something in the "Start in" field of a powershell shortcut like "c:\scripts" and have the powershell settle in at c:\scripts when it is finished initializing.  For me, however, powershell stays at c:\windows\system32.  

    bwo

    Sunday, October 17, 2010 10:02 PM
  • PowerShell v2.0 is installed in the v1.0 by design.

    ------------------------------------------------------------------

    As far as answering the original question, I'd suggest adding the following command to your PowerShell profile:

    Set-Location c:\scripts
    

    To Create a PowerShell Profile

    1. Create a folder in your Documents folder called WindowsPowerShell
    2. Create a file called profile.ps1 inside this folder
    3. Add any desired initialization commands to this file (see above) and save it
    4. Every time you launch PowerShell, the profile script will be executed

    More Information

    For more information about how PowerShell profiles work, see:

    Get-Help about_profiles
    

    Alternatively, visit this link: about_profiles

    Cheers


    Trevor Sullivan
    http://trevorsullivan.net
    Friday, October 29, 2010 7:51 AM
    Moderator
  • I realize this thread is pretty old but the reason why it doesn't work was not answered....

    I would guess that the reason this didn't work is powershell is running as an administrator. If you have the shortcut not set to run as admin and put c:\scripts in the start in path it should work. This is the same for the cmd.exe. The start path on one of these elevated executables will be %windir%\system32

    Thursday, August 17, 2017 1:02 AM