How do you set PowerShell's default directory?

前端 未结 13 1872
生来不讨喜
生来不讨喜 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:49

    Create a PowerShell profile as follows.

    1. Run PowerShell as administrator and execute the following command:

      Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

      This will permit PowerShell to run local scripts and scripts downloaded from the Internet that have been signed. Read more about this command in the documentation.

    2. In your Documents folder, find a folder named WindowsPowerShell for classic PowerShell or PowerShell for newer PowerShell Core. If it does not exist, that's ok; just create it.

    3. Create a new file named profile.ps1 in the WindowsPowerShell folder (or PowerShell for PowerShell Core).
    4. Open profile.ps1 and add the following command to set your default working directory:

      Set-Location C:\my\default\working\directory
      
    5. Open a new PowerShell window... the changes should have taken effect.

提交回复
热议问题