Pythonスクリプトから実行する必要がある非常に長いpowershellスクリプトがあります。PowerShell スクリプトは、コマンド ラインから実行すると正常に動作しますが、Python から実行すると失敗します。
問題を再現する次のコードに powershell スクリプトを簡略化しました。
Powershell スクリプト:
import-module WebAdministration
Add-Type -Path C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll
Set-WebConfigurationProperty '/system.webServer/proxy' -Name "enabled" -Value "true"
Python スクリプト:
import subprocess
print subprocess.check_output("powershell [pathToMyPowershellScript]");
cmd.exe から powershell スクリプトを実行すると、正常に動作し、何も出力されません。Python スクリプトを実行すると、次のエラーが発生します。
Set-WebConfigurationProperty : Retrieving the COM class factory for component
with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following
error: 80040154
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At [pathToMyPowershellScript]:3 char:1
+ Set-WebConfigurationProperty '/system.webServer/proxy' -Name "enabled" -Value "t ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo
: NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,
Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand
Python 2.7 と Powershell 1.0 を使用して、Windows 7 Professional (x64) で IIS 7.5 を実行しています。