How do you set PowerShell's default directory?

前端 未结 13 1763
生来不讨喜
生来不讨喜 2021-01-30 01:37

Is there a way to change PowerShell\'s default location?

How do you set PowerShell\'s default working directory?

13条回答
  •  爱一瞬间的悲伤
    2021-01-30 01:54

    With that, there seems to be some confusion on the "working directory" and PowerShell's "location". What most people here are doing, and saying to do is change PowerShell's "location". The "working directory" is actually different. Here is an article that explains it.

    For those who don't want to read the article: Open PowerShell and use what others have said to do Set-Location "C:\some\directory". Notice that your "working directory" is still where your PowerShell was opened at. Either "~" or "%SYSTEMROOT%\system32" depending on if you ran as administrator or not. To check the working directory, use [Environment]::CurrentDirectory.

    Note: in the article the author says to check the "working directory" by using this command:

    \[Environment\]::CurrentDirectory
    

    I am not sure if this works with older PowerShell versions, but with PowerShell 5 (and later) you have to use [Environment]::CurrentDirectory.

提交回复
热议问题