Powershell-Profil kann nicht mit Ruby 2.3 unter Windows geladen werden

489
brgsousa

Nach dem Upgrade von Ruby 2.2 auf Ruby 2.3 funktionierten Powershell-Aufrufe nicht mehr, da Powershell-Profile nicht geladen wurden.

1) Wenn ich eine Eingabeaufforderung öffne, funktioniert es:

C:\Users\administrador>powershell.exe ls   Directory: C:\Users\administrador   Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 26/06/2015 16:20 .android d---- 24/08/2015 16:25 .gem d-r-- 30/06/2017 11:27 Contacts d-r-- 06/07/2017 16:53 Desktop d-r-- 30/06/2017 11:27 Documents d-r-- 30/06/2017 11:27 Downloads d-r-- 30/06/2017 11:27 Favorites d-r-- 30/06/2017 11:27 Links d-r-- 30/06/2017 11:27 Music d-r-- 30/06/2017 11:27 Pictures d-r-- 30/06/2017 11:27 Saved Games d-r-- 30/06/2017 11:27 Searches d-r-- 30/06/2017 11:27 Videos -a--- 22/01/2015 11:18 1796 volshext.log 

2) Aber wenn Sie Ruby verwenden, funktioniert es nicht. Ich führe die Eingabeaufforderung als Administrator aus:

irb(main):002:0> system("powershell ls") File C:\Windows\SysWOW64\WindowsPowerShell\v1.0\profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. At line:1 char:2 + . <<<< 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\profile.ps1' + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException  File C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. At line:1 char:2 + . <<<< 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1' + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException  File C:\Users\administrador\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. At line:1 char:2 + . <<<< 'C:\Users\administrador\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException    Directory: C:\Users\administrador   Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 26/06/2015 16:20 .android d---- 24/08/2015 16:25 .gem d-r-- 30/06/2017 11:27 Contacts d-r-- 06/07/2017 16:53 Desktop d-r-- 30/06/2017 11:27 Documents d-r-- 30/06/2017 11:27 Downloads d-r-- 30/06/2017 11:27 Favorites d-r-- 30/06/2017 11:27 Links d-r-- 30/06/2017 11:27 Music d-r-- 30/06/2017 11:27 Pictures d-r-- 30/06/2017 11:27 Saved Games d-r-- 30/06/2017 11:27 Searches d-r-- 30/06/2017 11:27 Videos -a--- 22/01/2015 11:18 1796 volshext.log   => true 

Was kann falsch sein?

0

1 Antwort auf die Frage

1
Ben N

Es ist wahrscheinlich, dass die Ausführungsrichtlinie für die gesamte Maschine Set-ExecutionPolicy Unrestrictedin einer normalen PowerShell-Eingabeaufforderung festgelegt wurde. Auf einem 64-Bit-System gibt es zwei Versionen von PowerShell: eine 64-Bit- und eine 32-Bit-Version. In dieser Situation erhalten Sie normalerweise die 64-Bit-Version, wenn Sie PowerShell ausführen. Es scheint jedoch, dass Ruby ein 32-Bit-Prozess ist. Gemessen am Vorhandensein von SysWOW64in der Fehlermeldung startet 32-Bit-Ruby die 32-Bit-PowerShell, die nicht die gleiche Sicht auf das System hat wie die 64-Bit-PowerShell. Von Ruby gestartete PowerShell kann die geänderte Ausführungsrichtlinie nicht sehen. Daher wird das Profilskript nicht ausgeführt.

Führen Sie den Richtlinieneinstellungsbefehl an einer erhöhten 32-Bit-PowerShell-Eingabeaufforderung aus, um das Problem zu beheben. Eine davon erhalten Sie über den Eintrag "Windows PowerShell (x86)" in Start. Sie können die Richtlinie auch nur für Ihr Benutzerkonto festlegen:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser 

Das scheint über alle Bitnesses zu wirken. Wenn Sie die Profilskripts nicht zur Ausführung benötigen, haben Sie außerdem die Möglichkeit, das Laden von Profilen mit dem -noprofileSwitch zu deaktivieren powershell.