How do I change $pshome?

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of David Pike David Pike 1 year, 8 months ago.

  • Author
    Posts
  • #27320
    Profile photo of David Pike
    David Pike
    Participant

    I'm a new user and prefer not to use my Documents folder. Can I change the value of $pshome to an arbitrary folder on my computer?

  • #27321
    Profile photo of Don Jones
    Don Jones
    Keymaster

    $pshome is the PowerShell installation folder. You can't change that, no.

  • #27322
    Profile photo of David Pike
    David Pike
    Participant

    Aah, I see. So to use a different folder for data, I would have to set a new variable and use it explicitly to "cd" or "save to"?

  • #27324
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So... maybe I don't understand the situation.

    PowerShell does not automatically save anything to $pshome. Most commands that save something, such as Out-File, simply default to the current directory, whatever that might be. You can always specify an alternate path, along with the filename, if you want something saved elsewhere.

    I presume you're using the ISE, because you mentioned "save to." The ISE also defaults to saving to the current directory, whatever that is. It doesn't default to $pshome. Setting a variable doesn't change any of that behavior. If you want to save a script to C:\Script, just type "C:\Script\" before the filename. Same as anywhere else in Windows.

    The ISE may default to your Documents folder – like most other apps do – but you can specify any other directory.

  • #27325
    Profile photo of David Pike
    David Pike
    Participant

    Thanks again for your prompt and accurate reply. As I said, I am just learning PowerShell and must have misread something in Chapter 1. Yes your interpretation is correct and I get it now.

    Cheers
    David

You must be logged in to reply to this topic.