Skip to content

Instantly share code, notes, and snippets.

@MSAdministrator
Created May 21, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MSAdministrator/7d1544f8a01238489ea593dcb7461dfe to your computer and use it in GitHub Desktop.
Save MSAdministrator/7d1544f8a01238489ea593dcb7461dfe to your computer and use it in GitHub Desktop.
Update-MSITableSettings
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Update-MSITableSettings
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
$msiPath,
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
$field,
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
$newValue,
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
$Table
)
Begin
{
# Add Required Type Libraries
Add-Type -Path "C:\Program Files (x86)\WiX Toolset v4.0\bin\WixToolset.Dtf.WindowsInstaller.dll";
}
Process
{
# Open an MSI Database
$oDatabase = New-Object WixToolset.Dtf.WindowsInstaller.Database($msiPath, [WixToolset.Dtf.WindowsInstaller.DatabaseOpenMode]::Direct);
#Create a Select Query against an individual property
$sSQLQuery = "SELECT * FROM $Table WHERE Name = '$field'"
#Create and Execute a View object
[WixToolset.Dtf.WindowsInstaller.View]$oView = $oDatabase.OpenView($sSQLQuery)
$oView.Execute()
#Fetch the Result
$oRecord = $oView.Fetch()
$sProductVersion = $oRecord.GetString(2)
#Display Retrieved Field
"Manufacturer = $($sProductVersion)"
$oRecord.SetString("Value",$(($newValue | Out-String).Trim()))
$oView.Modify([WixToolset.Dtf.WindowsInstaller.ViewModifyMode]::Update,$oRecord)
#Close the Database
$oView.Close();
$oDatabase.Dispose();
}
End
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment