Powershell DSC:使用 DSC 脚本安装时出错

Powershell DSC: Error while installing using DSC Script

当我 运行 下面的脚本时,它会安装 Web 平台安装程序并安装 URLReWrite。但它以错误结束。

configuration SetupVm 
{ 
    node ("localhost") 
    { 
        Package WebPi_Installation
        {
            Ensure = "Present"
            Name = "Microsoft Web Platform Installer 5.0"
            Path = Join-Path $PSScriptRoot WebPlatformInstaller_amd64_en-US.msi
            ProductId = '4D84C195-86F0-4B34-8FDE-4A17EB41306A'
            Arguments = ''
            DependsOn = @("[WindowsFeature]IISMgmtConsole")
        }

        Package UrlRewrite
        {
            Ensure = "Present"
            Name = "URL Rewrite 2.0"
            Path = "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe"
            ProductId = ''
            Arguments = "/install /products:UrlRewrite2 /AcceptEula"
            DependsOn = @("[Package]WebPi_Installation")
        }
    } 
} 

SetupVm

Start-DscConfiguration -Path .\SetupVm -Wait -Verbose -Force

Validate-StandardArguments, Path was C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] The path extension was .exe VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] Ensure is Present VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] product is VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] product as boolean is False VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] The package URL Rewrite 2.0 is not installed VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] Validate-StandardArguments, Path was C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] The path extension was .exe VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] Package configuration starting VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] The binary is an EXE

VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] Starting C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe with /install /products:UrlRewrite2 /AcceptEula

VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] Starting process C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe with arguments /install /products:UrlRewrite2 /AcceptEula

VERBOSE: [tktestdsc4]: [[Package]UrlRewrite] The machine requires a reboot VERBOSE: [tktestdsc4]: LCM: [ End Set ] [[Package]UrlRewrite] in 55.5920 seconds.

PowerShell DSC resource MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: Package from

C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe was installed, but the specified ProductId and/or Name does not

match package details

  • CategoryInfo : InvalidOperation: (:) [], CimException

  • FullyQualifiedErrorId : ProviderOperationExecutionFailure

  • PSComputerName : localhost

The SendConfigurationApply function did not succeed.

  • CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException

  • FullyQualifiedErrorId : MI RESULT 1

  • PSComputerName : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.

VERBOSE: Time taken for configuration job to complete is 70.57 seconds

您没有指定 productId,因此它会尝试使用 productId 验证软件包是否已安装但失败(很明显)。

如果产品没有 productId,您可以使用脚本扩展安装它,如果有,请将 productId 添加到 URL Rewrite 资源

对于任何重新访问此问题的人,对我们有用的解决方案是使用以下方法手动安装:

.\WebpiCmd-x64.exe /install /products:UrlRewrite2 /AcceptEula

然后 运行 在 powershell 中执行以下操作:

get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

导致:

{9BCA2118-F753-4A1E-BCF3-5A820729965C} IIS URL Rewrite Module 2

然后我们把这个productId添加到对应名称的dsc中,等等:

Package URLRewriteInstallation
{
  Ensure = "Present"
  Name = "IIS URL Rewrite Module 2"
  Path = $Node.WebPiCmdPath
  ProductId = '9BCA2118-F753-4A1E-BCF3-5A820729965C'
  Arguments = "/install /products:UrlRewrite2 /AcceptEula"
  DependsOn = @("[Package]WebPlatformInstaller", "[Script]PIProxy")
}

urlrewrite 安装成功