forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSPInfo.ps1
More file actions
55 lines (48 loc) · 2.4 KB
/
MSPInfo.ps1
File metadata and controls
55 lines (48 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
Extract MSP information
.DESCRIPTION
This script will extract MSP file information from the metadata table. It has been written to be able to read data from a lot of different MSP files, including Microsoft Office updates and most application patches. There are some MSP files that were not populated with the metadata table, therefor no data is obtainable.
.PARAMETER MSPFileName
Name of the MSP File to call
.PARAMETER MSPProperty
Property to extract information
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.122
Created on: 6/15/2016 4:07 PM
Created by: Mick Pletcher
Filename: MSPInfo.ps1
===========================================================================
#>
param
(
[ValidateNotNullOrEmpty()]$MSPFileName = 'accessde-en-us.msp',
[ValidateNotNullOrEmpty()]$MSPProperty = 'KBArticle Number'
)
function Get-MSPFileInfo {
param
(
[Parameter(Mandatory = $true)][IO.FileInfo]$Path,
[Parameter(Mandatory = $true)][ValidateSet('Classification', 'Description', 'DisplayName', 'KBArticle Number', 'ManufacturerName', 'ReleaseVersion', 'TargetProductName')][string]$Property
)
try {
#Creating windows installer object
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
#Loads the MSI database and specifies the mode to open it in by the last number on the line
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($Path.FullName, 32))
#Specifies to query the MSIPatchMetadata table and get the value associated with the designated property
$Query = "SELECT Value FROM MsiPatchMetadata WHERE Property = '$($Property)'"
#Open up the property view
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
#Retrieve the associate Property
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
#Retrieve the associated value of the retrieved property
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
return $Value
} catch {
Write-Output $_.Exception.Message
}
}
Get-MSPFileInfo -Path $MSPFileName -Property $MSPProperty