Created
May 21, 2016 04:15
-
-
Save MSAdministrator/7d1544f8a01238489ea593dcb7461dfe to your computer and use it in GitHub Desktop.
Update-MSITableSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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