• I would like to add following snipped

    function get-msiinfo
    <#
    .SYNOPSIS
    funktion to get MSI details
    .DESCRIPTION
    get ProductCode, ProductVersion, ProductName
    .PARAMETER $Path
    specifies the path of MSI file
    .PARAMETER $Property
    Properies can be specified for ProductCode, ProductVersion, ProductName
    .EXAMPLE
    get-msiinfo -Path C:\temp\file.msi -Property ProductCode
    get-msiinfo -Path C:\temp\file.msi -Property ProductVersion
    get-msiinfo -Path C:\temp\file.msi -Property ProductName
    #>
        {
        [CmdletBinding()]
        param(
            [parameter(Mandatory=$true)]
            [IO.FileInfo]$Path,
            [parameter(Mandatory=$true)]
            [ValidateSet("ProductCode","ProductVersion","ProductName")]
            [string]$Property
            )
        try {
            $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
            $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$WindowsInstaller,@($Path.FullName,0))
            $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
            $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 $Value
            }
        catch {
            Write-Output $_.Exception.Message
            }
        }

    The error appearing shows following:

    Access denied by security policy
    Your request is blocked by a security policy rule.

    What causes the error.

    https://www.ads-software.com/plugins/code-snippet-library/

  • The topic ‘cannot add a snippet’ is closed to new replies.