A few weeks ago we have started with the preparation for introducing Microsoft Office 2013 and Internet Explorer 11. As with every introduction of new software it’s all about compatibility. During the course of testing applications we were informed that some of them caused an issue due to hard coded paths. Each application is going to be installed anyway so that application owners can conduct testing, but at the same time I thought, it would be nice if we could identify potentially affected applications upfront without having to go through an actual install.
Here’s an example of an application that has a hard coded path to Microsoft Office 2010. The Directory is defined as Office14 which translates to the Office 2010 Installation directory.
As most of you probably know, a Windows Installer file is a database that contains all the necessary information for the installation of an application. In order to query the files referenced within the Windows Installer database, we have to look at the following database tables.
Let’s start with the File Table. In the below example we see that this Application consists of two files. The File Table contains the following attributes: File, Component_, FileName, FileSize, Version, Language, Attributes and Sequence.
To find out in which directory this file installs, we first have to look at the Component table which has the following attributes: Component, ComponentId, Directory_, Attributes, Condition and KeyPath.
To link these two tables, we use the FileName attribute of the file table and Component attribute of the Component table. So far we know that the file iPublish_.dotm.lnk is going to be stored into the STARTUP folder. Now we only need to find out where the STARTUP folder is going to be, so we are going to look at the Directory table.
And there it is, the STARTUP directory. But we still don’t know where the file is going to be stored, as we first need to resolve the other Directory entries. If you study the directory table for a while, you notice that there is some logic in here.
To link the Directory table with the File and Component data, we join the Component table Directory_ attribute with the Directory table Directory attribute. However this still doesn’t give us the information where the file is going to be stored on the system, unless we would try to resolve the various entries within the Directory table, that to be honest would end up in a complex script (at least for me).
But then I found this forum post on stackoverflow discussing how to resolve MSI paths programmatically by calling the CostInitialize and CostFinalize Actions. The result of calling these actions is that the full file paths are resolved.
So now that we know what pieces need to be tied together, let’s turn this into a PowerShell script. I had a few challenges here. When calling the Windows installer object to invoke the CostInitialize and CostFinalize actions directly from within the PowerShell script that contains the Get-MSIFileInfo function, the Windows installer session would not close. So had to launch this in a separate process and then process the results within the calling script. This is why you find a complete PowerShell script defined in the $launchmsiscript variable.
When running the function against one or multiple Windows installer databases, the results are exported into a text file containing the following attributes for each file.
MSIFileFullname
MSIProductName
MSIProductVersion
Manufacturer
MSIProductCode
File
Component
FileName
FileSize
Version
Directory
Directory_Parent
DefaultDir
TargetPath
The entire script can be downloaded from here
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
function Get-MSIFileInfo() { <# .SYNOPSIS This function retrieves File information from Windows Installer (MSI) files .DESCRIPTION This fucntion uses the Windows Instaler COM object to retrieve file information from the Windows Installer database. The script can be used for analyzing content of Windows Installer databases without the need of having to initiate an actual install. The function retrieves the following information for each file referenced in the Windows Installer Database MSIFileFullname : C:\TEMP\cmcollctr_1.0.0.11.msi MSIProductName : Collection Commander for Configuration Manager MSIProductVersion : 1.0.0.11 Manufacturer : Zander Tools MSIProductCode : {38253945-0CBC-4A05-BCAF-CE979EA4AAEF} File : sccmclictr.automation.dll Component : sccmclictr.automation.dll FileName : sccmcl~1.dll|sccmclictr.automation.dll FileSize : 435576 Version : 0.0.0.55 Directory : APPDIR Directory_Parent : TARGETDIR DefaultDir : APPDIR:. TargetPath : C:\Program Files (x86)\Collection Commander for Configuration Manager .EXAMPLE Get-MSIFileInfo -Installerfile "C:\TEMP\cmcollctr_1.0.0.11.msi" This command processes the specified file(s) and stores the file information results into a csv file located in the same folder as the script. .EXAMPLE Get-MSIFileInfo -IstallerFolder "C:\TEMP\MSI" This command processes all MSI files stored under c:\temp\msi and stores the file information results into a csv file located in the same folder as the script. .EXAMPLE Get-MSIFileInfo -Installerfile "C:\TEMP\cmcollctr_1.0.0.11.msi" -OutPutFile "C:\TEMP\msifileresults.csv" This command processes the specified file and stores the file informatoin results into the spevified output file. .PARAMETER InstallerFile The path to a Windows Installer file. .PARAMETER InstallerFolder The path of the folder containing Wwindows Installer files .PARAMETER OutPutFile (Optional) The path to the output file. If no Output file is specified the results are stored into a csv file located within the script file folder. .LINKS MSDN Windows Installer http://msdn.microsoft.com/en-us/library/aa369432(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/aa371653(v=vs.85).aspx http://stackoverflow.com/questions/23903254/advanced-installer-powershell-script-set-property .NOTES Version 1.1.0 by Alex Verboon Credits weberik's post at stackoverflow for the vb script code and Claude Henchoy for the conversion into PS https://stackoverflow.com/questions/17543132/how-can-i-resolve-msi-paths-in-vbscript#new-answer Adam Bertram's Get-MSIProperties script got me started with how to read content from MSI files http://gallery.technet.microsoft.com/scriptcenter/Get-all-native-properties-e4e19180 Trevor Sullivan's memory usage snippet http://trevorsullivan.net/2012/01/23/powershell-prompt-function-to-monitor-memory-usage/ #> [CmdletBinding()] param ( [Parameter(ParameterSetName="File", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, Position=0, HelpMessage='What is the path of the Windows Installer file to query?')] [String[]]$InstallerFile, [Parameter(ParameterSetName="Directory", Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, Position=0, HelpMessage='What is the path containing the Windows Installer files to query?')] [string]$InstallerFolder, [Parameter(Mandatory=$false, Position=1, HelpMessage='What is the path of the output file')] [String]$OutPutFile ) begin { # Check what parameter was used File or Folder switch ($PsCmdlet.ParameterSetName) { "File" { # Check if the Windows Installer file(s) exists, exit if not ForEach ($checkfile in $InstallerFile) { if (!(Test-Path -literalpath $checkfile)) { throw "File '{0}' does not exist" -f $checkfile} } } "Directory"{ # Check if the provided Directory exists, exit if not if (!(Test-Path -Path $InstallerFolder)) { throw "Folder '{0}' does not exist" -f $InstallerFolder } Else { # When a folder is provided, retrieve all Windows installer files # in the folder and subfolders $InstallerFile = (Get-ChildItem -Path "$InstallerFolder\*.MSI" -Recurse -File).FullName } } } # end switch # Check if an output file was specified if ($PSBoundParameters.ContainsKey("OutPutFile")) { # no Output file parameter specified so we use the default output defined below $msifileinfo_output = $OutPutFile } Else { # construct the results output file $timestamp = $((get-date).tostring("MMddyyyyHHmmss")) $filename = "MSI_FileInfo" + "_" + $timestamp + ".txt" $msifileinfo_output = $PSScriptRoot + "\" + "$filename" } # Windows Installer COM object $com_object = New-Object -com WindowsInstaller.Installer # construct the temp powershell script file name $tmpfile = [guid]::NewGuid().Guid + ".ps1" $tmpfld = "$env:Temp\" $tmpps = $tmpfld + $tmpfile # $launchmsiscript contains the powershell code used to run the Windows Installer CostInitialize and # Costfinalize actions # http://msdn.microsoft.com/en-us/library/aa368050(v=vs.85).aspx # http://msdn.microsoft.com/en-us/library/aa368048(v=vs.85).aspx # we have to launch a separate powershell process as otherwise the Windows Installer process remains open # the below code is stored into a temporary ps1 file that is then launched from the below process. $launchmsiscript = @" <# .Synopsis This function invokes the Widnows Installer CostFinalize action .DESCRIPTION This function invokes the Widnows Installer CostFinalize action and then provides the filename, component and resolved path of the path as output .EXAMPLE Invoke-MSICostFinalize -FileName "C:\TEMP\cmcollctr_1.0.0.11.msi" .NOTES Credits weberik's post at stackoverflow for the vb script code to run the MSI costfinalize action https://stackoverflow.com/questions/17543132/how-can-i-resolve-msi-paths-in-vbscript#new-answer Claude Henchoz for converting the above referenced vb script code into powershell #> function Invoke-MSICostFinalize { [CmdletBinding()] Param ( # Param1 help description [Parameter(Mandatory=`$true, ValueFromPipelineByPropertyName=`$true, Position=0)] [String]`$FileName ) Begin { # Check if the Installer File exists if (!(Test-Path -literalpath `$FileName)) { throw "File '{0}' does not exist" -f `$FileName} } Process{ # Installer init, OpenDatabase, OpenPackage `$Installer = New-Object -ComObject "WindowsInstaller.Installer" `$DB = `$Installer.GetType().InvokeMember("OpenDatabase","InvokeMethod",`$Null,`$Installer,@(`$FileName, 0)) `$Session = `$Installer.GetType().InvokeMember("OpenPackage","InvokeMethod",`$Null,`$Installer,@(`$DB, 0)) # CostInitialize, CostFinalize `$Session.GetType().InvokeMember("DoAction","InvokeMethod",`$Null,`$Session,@("CostInitialize", 0)) `$Session.GetType().InvokeMember("DoAction","InvokeMethod",`$Null,`$Session,@("CostFinalize", 0)) # Add Query `$View = `$DB.GetType().InvokeMember("OpenView","InvokeMethod",`$Null,`$DB, @("SELECT File, Directory_, FileName, Component_, Component FROM File,Component WHERE Component=Component_ ORDER BY Directory_", 0) ) # Execute Query `$View.GetType().InvokeMember("Execute","InvokeMethod",`$Null,`$View,@(0)) # Fetch 1st record `$Record = `$View.GetType().InvokeMember("Fetch","InvokeMethod",`$Null,`$View,@(0)) do { # Fill variables `$File = `$Record.GetType().InvokeMember("StringData","GetProperty",`$Null,`$Record,@(1,0)) `$DirectoryName = `$Record.GetType().InvokeMember("StringData","GetProperty",`$Null,`$Record,@(2,0)) `$FileName = `$Record.GetType().InvokeMember("StringData","GetProperty",`$Null,`$Record,@(3,0)) `$Components = `$Record.GetType().InvokeMember("StringData","GetProperty",`$Null,`$Record,@(4,0)) # Split filename try { `$FileName = `$FileName.Split("|")[1] } catch {} # Resolve Directory `$ResolvedDirectory = `$Session.GetType().InvokeMember("TargetPath","GetProperty",`$Null,`$Session,@(`$DirectoryName, 0)) # Output `$outline = `$ResolvedDirectory + `$FileName + "," + `$Components write-output `$outline # Get next record `$Record = `$View.GetType().InvokeMember("Fetch","InvokeMethod",`$Null,`$View,@(0)) } while (`$Record) } End{} } # end function If ([string]::IsNullOrEmpty(`$args) -ne `$true) { Invoke-MSICostFinalize -FileName "`$args" } Else { "Input Parameter -FileName is missing" } "@ #write the temporary powershell script file $launchmsiscript | Out-File -FilePath $tmpps -NoClobber -Encoding ascii } process { $ParentID = 1 $swcount = $InstallerFile.count $si=1 ForEach ($msifile in $InstallerFile) { $FilePath = [IO.FileInfo[]]$msifile Write-Progress -id $ParentID -Activity "Processing $si / $swcount" -Status "$msifile" -PercentComplete (($si / $swcount) * 100) # construct the temp resolved path output file $tmpfile = [guid]::NewGuid().Guid + ".txt" $tmpfld = "$env:Temp\" $tmprpaths = $tmpfld + $tmpfile # launch the temp powershell script to resolve the MSI paths Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Resolving paths" -PercentComplete 0 $resolvedpath = powershell.exe -NoLogo -file "$tmpps" "$FilePath" Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Resolving paths completed" -PercentComplete 100 # store the results into a tmp file $resolvedpath | Out-File -FilePath $tmprpaths -Encoding ascii # bulid the resolved paths table $in = 0 $resolvedpathdetails = @() while ($in -lt $resolvedpath.Count) { $fullpath = $resolvedpath.item($in).split(",")[0] $component = $resolvedpath.item($in).split(",")[1] $in = $in + 1 $rpath = New-Object -TypeName psobject $rpath | Add-Member -MemberType NoteProperty -Name "FullPath" -Value $fullpath $rpath | Add-Member -MemberType NoteProperty -Name "Component" -Value $component $resolvedpathdetails += $rpath } try { # -------------------------------------------------------------------------------------------------# # Open Database 1 # -------------------------------------------------------------------------------------------------# Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Opening Database" -PercentComplete 0 $database = $com_object.GetType().InvokeMember( "OpenDatabase", "InvokeMethod", $Null, $com_object, @($FilePath.FullName, 0) ) # -------------------------------------------------------------------------------------------------# # MSI Property Information 2 # -------------------------------------------------------------------------------------------------# Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Gathering Property Information" -PercentComplete ((5/100*1) *100) $Propertyquery = "SELECT * FROM Property" $PropertyView = $database.GetType().InvokeMember( "OpenView", "InvokeMethod", $Null, $database, ($Propertyquery) ) $PropertyView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $PropertyView, $Null) $Propertyrecord = $PropertyView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $PropertyView, $Null ) $properties_table = @{} while ($Propertyrecord -ne $null) { $Prop = $Propertyrecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $Propertyrecord, 1) $value = $Propertyrecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $Propertyrecord, 2) $properties_table.Add("$($prop)","$($value)") $Propertyrecord = $PropertyView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $PropertyView, $Null ) } # -------------------------------------------------------------------------------------------------# # MSI Directory Information 3 # -------------------------------------------------------------------------------------------------# Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Gathering Directory Information" -PercentComplete ((5/100*2) *100) $dirquery = "SELECT * FROM Directory" $dirView = $database.GetType().InvokeMember( "OpenView", "InvokeMethod", $Null, $database, ($dirquery) ) $dirView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $dirView, $Null) $dirrecord = $dirView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $dirView, $Null ) $directory_table = @{} while ($dirrecord -ne $null) { $Directory = $dirrecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $dirrecord, 1) $Directory_Parent = $dirrecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $dirrecord, 2) $DefaultDir = $dirrecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $dirrecord, 3) $directory_table.Add("$Directory",("$Directory_Parent","$DefaultDir")) $dirrecord = $dirView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $dirView, $Null ) } # -------------------------------------------------------------------------------------------------# # MSI File Information 4 # -------------------------------------------------------------------------------------------------# Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Gathering File Information" -PercentComplete ((5/100*3) *100) $filequery = "SELECT File,Component_,FileName,FileSize,Version FROM File" $fileView = $database.GetType().InvokeMember( "OpenView", "InvokeMethod", $Null, $database, ($filequery) ) $fileView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $fileView, $Null) $filerecord = $fileView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $fileView, $Null ) $files_table = @{} while ($filerecord -ne $null) { $file = $filerecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $filerecord, 1) $component = $filerecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $filerecord, 2) $filename = $filerecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $filerecord, 3) $filesize = $filerecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $filerecord, 4) $fileversion = $filerecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $filerecord, 5) $files_table.Add("$File",("$Component","$filename","$filesize","$fileversion")) $filerecord = $fileView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $fileView, $Null ) } # -------------------------------------------------------------------------------------------------# # MSI Component Information 5 # -------------------------------------------------------------------------------------------------# Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Gathering Component Information" -PercentComplete ((5/100*4) *100) $compquery = "SELECT * FROM Component" $compView = $database.GetType().InvokeMember( "OpenView", "InvokeMethod", $Null, $database, ($compquery) ) $compView.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $compView, $Null) $comprecord = $compView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $compView, $Null ) $components_table = @{} while ($comprecord -ne $null) { $component = $comprecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $comprecord, 1) $componentid = $comprecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $comprecord, 2) $directory = $comprecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $comprecord, 3) $keypath = $comprecord.GetType().InvokeMember("StringData", "GetProperty", $Null, $comprecord, 4) $components_table.Add("$component",("$componentid","$directory","$keypath")) $comprecord = $compView.GetType().InvokeMember( "Fetch", "InvokeMethod", $Null, $compView, $Null ) } Write-Progress -ParentId $ParentID -Activity "Initialization" -Status "Completed Gathering Information" -PercentComplete ((5/100*5) *100) # ------------------------------------------------------------------------------------------# # Putting it together # ------------------------------------------------------------------------------------------# # Get MSI Property data $MSIFileFullname = ($FilePath.FullName) $MSIProductName = $properties_table["ProductName"] $MSIProductVersion = $properties_table["ProductVersion"] $Manufacturer = $properties_table["Manufacturer"] $MSIProductCode = $properties_table["ProductCode"] # load the tmp resolved paths dat into a variable $rpf = Get-Content -Path $tmprpaths # -------------------------------------------------------------------------------------------------# # Create the dataset # -------------------------------------------------------------------------------------------------# $msi_fileprops = @() $fc=1 $sw = [System.Diagnostics.Stopwatch]::StartNew() $totalfiles = $files_table.count ForEach($item in $files_table.GetEnumerator()){ $msifileinfo = New-Object -TypeName psobject # MSI Properties data $msifileinfo | Add-Member -MemberType NoteProperty -Name "MSIFileFullname" -Value $MSIFileFullname $msifileinfo | Add-Member -MemberType NoteProperty -Name "MSIProductName" -Value $MSIProductName $msifileinfo | Add-Member -MemberType NoteProperty -Name "MSIProductVersion" -Value $MSIProductVersion $msifileinfo | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value $Manufacturer $msifileinfo | Add-Member -MemberType NoteProperty -Name "MSIProductCode" -Value $MSIProductCode # MSI File data $msifileinfo | Add-Member -MemberType NoteProperty -Name "File" -Value $item.Name $msifileinfo | Add-Member -MemberType NoteProperty -Name "Component" -Value $item.Value[0] $msifileinfo | Add-Member -MemberType NoteProperty -Name "FileName" -Value $item.Value[1] $msifileinfo | Add-Member -MemberType NoteProperty -Name "FileSize" -Value $item.Value[2] $msifileinfo | Add-Member -MemberType NoteProperty -Name "Version" -Value $item.Value[3] # Get the Directory from the components table $msifileinfo | Add-Member -MemberType NoteProperty -Name "Directory" -Value ($cd = $components_table["$($msifileinfo.Component)"][1]) # Get the Parent Directory from the directory table $msifileinfo | Add-Member -MemberType NoteProperty -Name "Directory_Parent" ($dp = $directory_table["$($msifileinfo.Directory)"][0]) # Get the Default Diectory from the directory table $msifileinfo | Add-Member -MemberType NoteProperty -Name "DefaultDir" ($dd = $directory_table["$($msifileinfo.Directory)"][1]) # Get the resolved path information #$rp = Get-Content -Path $tmprpaths | Select-String "$($msifileinfo.Component)" | Select-Object -First 1 $rp = $rpf | Select-String "$($msifileinfo.Component)" | Select-Object -First 1 #$rp = Get-Content -Path $tmprpaths -filter "$($msifileinfo.Component)" | Select-Object -First 1 $rp = $rp.ToString().split(",")[0] # because the above command sometimes returns multiple values, we have to check whether we have # just a string or an array, if we get an array we just take the first entry to get the path information if ($rp -is [array] -eq $true) { $msifileinfo | Add-Member -MemberType NoteProperty -Name "TargetPath" -Value ([System.IO.Path]::GetDirectoryName($rp[0])) } Else { $msifileinfo | Add-Member -MemberType NoteProperty -Name "TargetPath" -Value ([System.IO.Path]::GetDirectoryName($rp)) } $msi_fileprops += $msifileinfo $fc++ # to prevent write-progress from slowing down the process, only display process every 1000 milisecnds if ($sw.Elapsed.TotalMilliseconds -ge 1000) { $curmemusage = "$('{0:n2}' -f ([double](Get-Process -Id $pid).WorkingSet/1MB)) MB" Write-Progress -ParentId $ParentID -Activity "Retrieving Files" -Status "Processed $fc of $totalfiles files, Memory Usage: $curmemusage" -PercentComplete (($fc / $totalfiles) * 100) $sw.Reset(); $sw.Start() } } # end while file info # Delete the temp resolved path output file Remove-item -Path "$tmprpaths" -Force # dump the results into the text file Write-Progress -ParentId $ParentID -Activity "Processing results" -Status "storing results into log file" -PercentComplete 100 $msi_fileprops | Select-Object * | export-csv -Path $msifileinfo_output -NoClobber -NoTypeInformation -Append $si++ } catch { # show the error but continue Write-Output "Failed to get MSI file information the error was: {0}." -f $_ } } # end for each msi file } # end process End { # remove the temp ps script Remove-Item -Path "$tmpps" -Force } } # end function |
Thanks for this, I have a load of vbscripts for messing with MSIs but nothing in PowerShell yet! Something you might want to add, packages made by Visual Studio and some other tools set the main install dir via a custom action, so you may want to add support for that too.