Last active
July 31, 2019 07:32
-
-
Save grenade/3979bb88e8dc224fe9d94f839c59cf8d to your computer and use it in GitHub Desktop.
Extract a Product Name and Product Id (ProductCode) from an MSI file
This file contains hidden or 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
Remove-Item -Path '.\Get-MSIProperties.ps1' -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-MSIProperties.ps1', '.\Get-MSIProperties.ps1') | |
. .\Get-MSIProperties.ps1 | |
foreach ($installer in @('googlechromestandaloneenterprise.msi', 'googlechromestandaloneenterprise64.msi')) { | |
Write-Host '----------------------------------------------------' | |
Write-Host ('.\{0}' -f $installer) | |
Remove-Item -Path ('.\{0}' -f $installer) -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile(('https://dl.google.com/tag/s/dl/chrome/install/{0}' -f $installer), ('.\{0}' -f $installer)) | |
$msi = (Get-MSIProperties -Path ('.\{0}' -f $installer)) | |
$msi | |
Get-FileHash ('.\{0}' -f $installer) -Algorithm 'SHA512' | |
Write-Host '----------------------------------------------------' | |
} |
This file contains hidden or 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
$version = '4.9.1' | |
Remove-Item -Path '.\Get-MSIProperties.ps1' -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-MSIProperties.ps1', '.\Get-MSIProperties.ps1') | |
. .\Get-MSIProperties.ps1 | |
foreach ($arch in @('x86', 'x64')) { | |
Write-Host '----------------------------------------------------' | |
Write-Host ('.\mercurial-{0}-{1}.msi' -f $version, $arch) | |
Remove-Item -Path ('.\mercurial-{0}-{1}.msi' -f $version, $arch) -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile(('https://www.mercurial-scm.org/release/windows/mercurial-{0}-{1}.msi' -f $version, $arch), ('.\mercurial-{0}-{1}.msi' -f $version, $arch)) | |
$msi = (Get-MSIProperties -Path ('.\mercurial-{0}-{1}.msi' -f $version, $arch)) | |
$msi | |
Get-FileHash ('.\mercurial-{0}-{1}.msi' -f $version, $arch) -Algorithm 'SHA512' | |
Write-Host '----------------------------------------------------' | |
} |
This file contains hidden or 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
function Get-MSIProperties { | |
param ( | |
[Parameter(Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
[System.IO.FileInfo] $path, | |
[string[]] $properties = @('ProductCode', 'ProductVersion', 'ProductName', 'Manufacturer', 'ProductLanguage') | |
) | |
begin { | |
$windowsInstaller = (New-Object -ComObject WindowsInstaller.Installer) | |
} | |
process { | |
$table = @{} | |
$msi = $windowsInstaller.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $null, $windowsInstaller, @($Path.FullName, 0)) | |
foreach ($property in $properties) { | |
try { | |
$view = $msi.GetType().InvokeMember('OpenView', 'InvokeMethod', $null, $msi, ("SELECT Value FROM Property WHERE Property = '$($property)'")) | |
$view.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $view, $null) | |
$record = $view.GetType().InvokeMember('Fetch', 'InvokeMethod', $null, $view, $null) | |
$table.add($property, $record.GetType().InvokeMember('StringData', 'GetProperty', $null, $record, 1)) | |
} | |
catch { | |
$table.add($property, $null) | |
} | |
} | |
$msi.GetType().InvokeMember('Commit', 'InvokeMethod', $null, $msi, $null) | |
$view.GetType().InvokeMember('Close', 'InvokeMethod', $null, $view, $null) | |
$msi = $null | |
$view = $null | |
return $table | |
} | |
end { | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($windowsInstaller) | Out-Null | |
[System.GC]::Collect() | |
} | |
} |
This file contains hidden or 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
$version = '2.10.2150' | |
Remove-Item -Path '.\Get-MSIProperties.ps1' -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-MSIProperties.ps1', '.\Get-MSIProperties.ps1') | |
. .\Get-MSIProperties.ps1 | |
Write-Host '----------------------------------------------------' | |
Write-Host ('.\nxlog-ce-{0}.msi' -f $version) | |
Remove-Item -Path ('.\nxlog-ce-{0}.msi' -f $version) -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile(('https://nxlog.co/system/files/products/files/348/nxlog-ce-{0}.msi' -f $version), ('.\nxlog-ce-{0}.msi' -f $version)) | |
$msi = (Get-MSIProperties -Path ('.\nxlog-ce-{0}.msi' -f $version)) | |
$msi | |
Get-FileHash ('.\nxlog-ce-{0}.msi' -f $version) -Algorithm 'SHA512' | |
Write-Host '----------------------------------------------------' |
This file contains hidden or 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
$versions = @('3.6.3', '3.7.3') | |
New-Item -ItemType Directory -Force -Path @('.\public', '.\public\build') | |
Remove-Item -Path '.\Get-MSIProperties.ps1' -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-MSIProperties.ps1', '.\Get-MSIProperties.ps1') | |
. .\Get-MSIProperties.ps1 | |
foreach ($version in $versions) { | |
foreach ($arch in @('win32', 'amd64')) { | |
$occManifest = @() | |
$ttManifest = @() | |
foreach ($component in @('core', 'core_d', 'core_pdb', 'dev', 'dev_d', 'doc', 'exe', 'exe_d', 'exe_pdb', 'launcher', 'lib', 'lib_d', 'lib_pdb', 'path', 'pip', 'tcltk', 'tcltk_d', 'tcltk_pdb', 'test', 'test_d', 'test_pdb', 'tools', 'ucrt')) { | |
Write-Host '----------------------------------------------------' | |
Write-Host ('.\python-{0}-{1}-{2}.msi' -f $version, $arch, $component) | |
Remove-Item -Path ('.\python-{0}-{1}-{2}.msi' -f $version, $arch, $component) -Force -ErrorAction SilentlyContinue | |
(New-Object System.Net.WebClient).DownloadFile(('https://www.python.org/ftp/python/{0}/{1}/{2}.msi' -f $version, $arch, $component), ('.\python-{0}-{1}-{2}.msi' -f $version, $arch, $component)) | |
$msi = (Get-MSIProperties -Path ('.\python-{0}-{1}-{2}.msi' -f $version, $arch, $component)) | |
$msi | |
$sha512 = (Get-FileHash ('.\python-{0}-{1}-{2}.msi' -f $version, $arch, $component) -Algorithm 'SHA512') | |
$sha512 | |
$occManifestComponent = [ordered]@{ | |
ComponentName=('python_{0}_{1}_{2}' -f $version.Replace('.', '_'), $arch, $component); | |
ComponentType='MsiInstall'; | |
Url=('https://www.python.org/ftp/python/{0}/{1}/{2}.msi' -f $version, $arch, $component); | |
Name=$msi.ProductName; | |
ProductId=$msi.ProductCode.Trim("{}"); | |
sha512=$sha512.Hash.ToLower(); | |
} | |
$ttManifestComponent = [ordered]@{ | |
url=('https://www.python.org/ftp/python/{0}/{1}/{2}.msi' -f $version, $arch, $component); | |
filename=('python-{0}-{1}-{2}.msi' -f $version.Replace('.', '-'), $arch, $component); | |
} | |
$occManifest += $occManifestComponent | |
$ttManifest += $ttManifestComponent | |
$occManifestComponent | ConvertTo-Json | |
Write-Host '----------------------------------------------------' | |
} | |
$occManifest | ConvertTo-Json | Out-File -FilePath ('.\public\build\python-{0}-{1}.json' -f $version, $arch) | |
$ttManifest | ConvertTo-Json | Out-File -FilePath ('.\public\build\tooltool-python-{0}-{1}.json' -f $version, $arch) | |
} | |
} |
This file contains hidden or 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
provisionerId: aws-provisioner-v1 | |
workerType: gecko-1-b-win2012 | |
retries: 5 | |
priority: highest | |
created: '2018-09-19T15:47:49.218Z' | |
deadline: '2018-09-20T15:47:49.218Z' | |
expires: '2018-10-17T15:47:49.218Z' | |
scopes: [] | |
payload: | |
maxRunTime: 3600 | |
artifacts: | |
- name: 'public/build' | |
type: directory | |
path: 'public/build' | |
command: | |
- powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-HgMsiProperties.ps1?{0}' -f [guid]::newguid()))" | |
- powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-NxLogMsiProperties.ps1?{0}' -f [guid]::newguid()))" | |
- powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-PythonMsiProperties.ps1?{0}' -f [guid]::newguid()))" | |
- powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d/raw/Get-GoogleChromeMsiProperties.ps1?{0}' -f [guid]::newguid()))" | |
metadata: | |
owner: [email protected] | |
source: 'https://gist.github.com/grenade/3979bb88e8dc224fe9d94f839c59cf8d' | |
description: Extract Product Id and Name from MSI files | |
name: GetMSIProperties | |
tags: | |
os: windows | |
createdForUser: [email protected] | |
worker-implementation: generic-worker | |
extra: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment