Using Powershell as terminal in IntelliJ IDEA IDEs like PyCharm, PHPStorm or RubyMine

后端 未结 11 1377
太阳男子
太阳男子 2020-12-24 01:53

I have been attempting to run powershell as my terminal on windows in pycharm, so I did the following:

\"enter

11条回答
  •  离开以前
    2020-12-24 02:26

    As mentioned in other answers, if after setting powershell.exe as your terimal in IntelliJ → Settings → Tools → Terminal → Shell path it throws UnAuthorizedAccess errors, normal way to solve this is to alter execution policy:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    

    Note that Unrestricted level is the least secure of all, and you're usually can go with RemoteSigned in order to disable unsigned scripts downloaded from the web until you manually remove Internet or Intranet Zone.Identifier from them, usually with Unlock button in file properties.

    However, you may run to an occasion when you're not able to change execution policy. Usually that's because of corporate security settings in Active Directory. In PowerShell, that corresponds to scopes MachinePolicy and UserPolicy. A primary symptom of this situation is the following message:

    Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of AllSigned. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".

    You can't set execution policies at this scopes with PowerShell or gpedit.msc. Attempts to change this settings directly in registry is also ineffective: they're applied on restart or login, but at the same time they're being re-imported from Active Directory. However, while you won't be able to run arbitrary PowerShell scripts all around, for profiles and other local scripts that's only modified manually there's still a solution:

    1. Run the following command in PowerShell to create ceritificate files root.pvk and root.cer - it will ask you to define and then confirm password to the certificate:

      makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss Root -sr localMachine
      
    2. In the same folder, run the following command to import generated certificate files as your self-signed certificate - it will ask for the password you're defined above:

      makecert -pe -n "CN=PowerShell User" -ss MY -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer
      
    3. Sign your profile script with the following command:

      Set-AuthenticodeSignature "[script path]" @(Get-ChildItem cert:\CurrentUser\My -codesign)[0]
      
    4. When running a script signed with self-ceritificate for the first time, PowerShell will ask you about trusting the certificate like this:

      The file [script path] is published by CN=PowerShell User. This publisher is not trusted on your system. Only run scripts from trusted publishers.

      [V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D")

      Answer A to always run self-signed certificates.

    Now your profile script won't cause any errors. However, note that signing a certificate adds a signature block in the end of your script containing its hash. If you're about to modify the script, remove that block and, after you're done with editing the script, sign it again by repeating step 3.

提交回复
热议问题