There's a script that we use at work, that is designed to add office update files with .msp office extension to a q:\ so they can be installed, so that when it comes to checking for updates, they are already installed.
the script deals with .msp files, but .msi files are located in the c:\windows\installer folder and they should be considered to.
How do I tweak the following script, so that it checks for .msi files as well as .msp files and adds it if the date is greater than the existing file (if applicable)
function Get-MsiDatabaseValue {
param (
[IO.FileInfo] $FilePath,
$Table,
$Tableproperty
)
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($FilePath.FullName, 32)
)
$q = "SELECT Value FROM $Table WHERE Property = '$TableProperty'"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)
$TableValue = $record.GetType().InvokeMember(
"StringData", "GetProperty", $Null, $record, 1
)
return $TableValue
} catch {
# throw "Failed to get MSI file version the error was: {0}." -f $_
}
}
$PackageName = get-msiDatabaseValue C:\Windows\Installer\9cc3aad.msp MsiPatchMetadata StdPackageName
$TargetProductName = get-msiDatabaseValue C:\Windows\Installer\9cc3aad.msp MsiPatchMetadata TargetProductName
Function CopyMsp ($Cachepath, $OrigFile, $Newfile) {
if ((Test-Path $Cachepath) -eq $false) {
mkdir -Path $Cachepath -Force
}
if ((Test-Path "$Cachepath\$Newfile") -eq $false) {
Copy-Item -Path $OrigFile -Destination "$Cachepath\$Newfile"
} else {
if ((Get-Item $OrigFile).CreationTime -gt (Get-Item "$Cachepath\$Newfile").CreationTime ) {
Copy-Item -Path $OrigFile -Destination "$Cachepath\$Newfile"
}
}
}
Get-ChildItem -Path C:\windows\installer -Filter *.msp | foreach {
$PackageName = get-msiDatabaseValue $_.fullname MsiPatchMetadata StdPackageName
$TargetProductName = get-msiDatabaseValue $_.fullname MsiPatchMetadata TargetProductName
$DisplayName = get-msiDatabaseValue $_.fullname MsiPatchMetadata DisplayName
if ($PackageName -ne $null) {
if ($DisplayName -like '*2007*') {
CopyMsp "Q:\sccm\Updates\Microsoft\Office\2007" $_.FullName $PackageName
#write-host "$PackageName $TargetProductName $DisplayName is 2007"
} elseif ($DisplayName -like '*2010*') {
#write-host "$PackageName $TargetProductName $DisplayName is 2010"
CopyMsp "Q:\sccm\Updates\Microsoft\Office\2010" $_.FullName $PackageName
} elseif ($DisplayName -like '*2013*') {
#write-host "$PackageName $TargetProductName $DisplayName is 2013"
CopyMsp "Q:\sccm\Updates\Microsoft\Office\2013" $_.FullName $PackageName
} elseif ($DisplayName -like '*SkyDrive Pro*') {
#write-host "$PackageName $TargetProductName $DisplayName is 2013"
CopyMsp "Q:\sccm\Updates\Microsoft\Office\2013" $_.FullName $PackageName
} else {
#write-host "$PackageName $TargetProductName $DisplayName is a mystery, or 2003"
}
}
}
exit 0
↧