AWS CodeDeploy Powershell脚本无法在IIS服务器中创建网站和池

Nee*_*hah 4 iis powershell amazon-web-services windows-server-2012-r2 aws-code-deploy

我有一个应用程序,使用AWS Codedeploy将其部署到运行Windows Server 2012 R2且安装了代码部署代理的EC2实例。

代码修订版已成功从S3存储桶下载到EC2实例,但是PowerShell脚本引发错误。

只是要通知您,在EC2实例中手动执行脚本时,脚本运行成功。

这是我的appspec.yml和before-install.bat

  • appspec.yml

    version: 0.0 os: windows files: - source: \index.html destination: C:\DemoApp\MySite hooks: BeforeInstall: - location: \before-install.bat timeout: 900

  • before-install.bat

    C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Import-Module WebAdministration; New-Item iis:\Sites\MySite -bindings @{protocol=\"http\";bindingInformation=\":80:\"} -physicalPath c:\DemoApp\MySite; New-Item IIS:\AppPools\MyPool; Set-ItemProperty IIS:\Sites\MySite -name applicationPool -value MyPool;}"

codedeploy-agent-deployments.log

脚本-\ before-install.bat C:\ Windows \ system32> C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ powershell.exe-命令“&{Set-ExecutionPolicy Unrestricted; Import-Module WebAdministration; New-Item iis :\ Sites \ MySite -bindings @ {protocol = \“ http \”; bindingInformation = \“:80:\”} -physicalPath c:\ DemoApp \ MySite; New-Item IIS:\ AppPools \ MyPool; Set-ItemProperty IIS :\ Sites \ MySite -name applicationPool -value MyPool;}“ New-Item:无法检索该cmdlet的动态参数。由于以下错误,未能为具有CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6}的组件检索COM类工厂:80040154未注册类(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG))。在第1行:char:71 +&{Set-ExecutionPolicy Unrestricted; 导入模块Web管理;新项目我...

小智 5

试试这个脚本:

if ($PSHOME -like "*SysWOW64*")
{
  Write-Warning "Restarting this script under 64-bit Windows PowerShell."

  & (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File `
    (Join-Path $PSScriptRoot $MyInvocation.MyCommand) @args

  Exit $LastExitCode
}

Import-Module WebAdministration; 
New-Item IIS:\AppPools\MyPool;
New-Item iis:\Sites\MySite -bindings @{protocol='http';bindingInformation=':80:'} -physicalPath c:\DemoApp\MySite;
Set-ItemProperty IIS:\Sites\MySite -name applicationPool -value MyPool
Run Code Online (Sandbox Code Playgroud)

请参阅http://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-deployments.html