繁体   English   中英

使用 Powershell DSC 安装可执行文件

[英]Installing executables with Powershell DSC

我正在尝试使用 PowerShell DSC 安装 Visual Studio 2013,但我遇到了一些问题,希望你们能帮我解决。 DSC 是否能够重新启动节点,然后继续安装 VS? 有谁知道这个错误是什么意思? “vs_ultimate.exe 已安装,但指定的 ProductId 和/或 Name 与包详细信息不匹配”

有没有人有任何更具体的例子来尝试使用这种方法安装 .exe?

有人如何找到 ProductID?

有人知道 ReturnCode 的确切语法吗?

任何帮助都会很棒!

如果您的系统已经安装了该软件,您可以使用以下方法找到 ProductID:

Get-WmiObject -Class Win32_Product | fl Name,Version,InstallDate,InstallSource,PackageName,IdentifyingNumber

示例输出:

Name              : Dell OpenManage Systems Management Software (64-Bit)
Version           : 7.3.0
InstallDate       : 20131009
InstallSource     : c:\Installs\OMSA\
PackageName       : SysMgmtx64.msi
IdentifyingNumber : {7CB08DC5-EA02-4076-BA7D-AD7736A3DE71}

Name              : Microsoft ASP.NET MVC 4 Runtime
Version           : 4.0.40804.0
InstallDate       : 20141111
InstallSource     : C:\windows\TEMP\IXP000.TMP\
PackageName       : AspNetMVC4.msi
IdentifyingNumber : {3FE312D5-B862-40CE-8E4E-A6D8ABF62736}

其中 IdentificationNumber 是您应该在包资源中使用的 GUID。 上述戴尔软件的示例:

package OMSA
{
        Name = 'Dell OpenManage Systems Management Software (64-Bit)'
        ...
        ProductId = '7CB08DC5-EA02-4076-BA7D-AD7736A3DE71'
        Arguments = ...
}

引用希思·斯图尔特的评论

ProductId 是 MSI 的 ProductCode,您可以通过在 Orca(Windows SDK 的一部分)中打开 MSI 来获取它,或者您可以从http://psmsi.codeplex.com安装我的模块并像这样获取它:

get-msitable <yourmsi.msi> -table Property | where { $_.Property -eq "ProductCode" }

该错误意味着您的 Package 资源的 Name 或 ProductId 与 msi 内容不匹配。

根据我的经验,找到这两个值的最简单方法是使用Carbon powershell 模块。

Install-Module Carbon

然后只需从 powershell 控制台运行:

msi "[path to your msi]"

注意:msi 是 Get-Msi 的别名

例子:

PS C:\Users\gigi\Downloads> msi .\node-v6.10.0-x64.msi

ProductName ProductVersion Manufacturer       ProductCode                         
----------- -------------- ------------       -----------                         
Node.js     6.10.0         Node.js Foundation 84f68739-3b44-4d36-abdb-2151a23c9c3d

将 ProductName 和 ProductCode 复制并粘贴到您的 DSC 包配置中,您就完成了。

我写了一个PowerShell函数来查找产品信息

Function Get-InstallerProductProperty
{
    # Define parameters
    Param($installerFilePath,
    $PropertyName)

    # Verify file exists
    if((Test-Path -Path $installerFilePath) -eq $true)
    {
        $path = $installerFilePath

        $comObjWI = New-Object -ComObject WindowsInstaller.Installer
        $MSIDatabase = $comObjWI.GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$comObjWI,@($Path,0))
        $Query = "SELECT Value FROM Property WHERE Property = '$PropertyName'"
        $results = $View = $MSIDatabase.GetType().InvokeMember("OpenView","InvokeMethod",$null,$MSIDatabase,($Query))
        $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
        $Record = $View.GetType().InvokeMember("Fetch","InvokeMethod",$null,$View,$null)
        $Value = $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,1)

        # Return the product id
        return $Value.Replace("{", "").Replace("}", "")
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM