[CmdletBinding()] param([Parameter(Mandatory)][string]$OutputPath) $ErrorActionPreference='Stop' Add-Type -Path (Join-Path $PSScriptRoot 'InstallerInventory.cs') $identity=[Security.Principal.WindowsIdentity]::GetCurrent() $session=[Diagnostics.Process]::GetCurrentProcess().SessionId $release=Get-Content -Raw (Join-Path $PSScriptRoot 'Release.json') | ConvertFrom-Json $local=[Environment]::GetFolderPath('LocalApplicationData') $installRoot=Join-Path $local 'Programs\PlotDirector Companion' $family=@([CompanionInstallerInventory]::Family($release.upgradeCode)) $baseline=@([CompanionInstallerInventory]::Product($release.baselineProductCode)) $current=@([CompanionInstallerInventory]::Product($release.productCode)) $ancestry=@();$next=$PID for($depth=0;$depth -lt 8 -and $next;$depth++){ $process=Get-CimInstance Win32_Process -Filter "ProcessId=$next" if(!$process){break} $ancestry+=@{id=$process.ProcessId;parent=$process.ParentProcessId;name=$process.Name;path=$process.ExecutablePath} $next=$process.ParentProcessId } $explorer=@(Get-CimInstance Win32_Process -Filter "Name='explorer.exe'" | Where-Object SessionId -eq $session | ForEach-Object { $owner=Invoke-CimMethod -InputObject $_ -MethodName GetOwnerSid @{id=$_.ProcessId;session=$_.SessionId;sid=$owner.Sid;matchesCurrentUser=$owner.Sid -eq $identity.User.Value} }) $registration=Get-ItemProperty 'HKCU:\Software\Microsoft\Office\Word\Addins\PlotDirector.WordAddIn' -ErrorAction SilentlyContinue | Select-Object Manifest,LoadBehavior,FriendlyName,Description $files=@(if(Test-Path $installRoot){Get-ChildItem $installRoot -File -Recurse | ForEach-Object { @{relative=$_.FullName.Substring($installRoot.Length+1);length=$_.Length;sha256=(Get-FileHash $_.FullName).Hash;version=[Diagnostics.FileVersionInfo]::GetVersionInfo($_.FullName).FileVersion} }}) $theme=Get-ItemPropertyValue 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name AppsUseLightTheme -ErrorAction SilentlyContinue $snapshot=@{ checkedUtc=[DateTime]::UtcNow.ToString('o');identity=$identity.Name;sid=$identity.User.Value;session=$session;profile=$env:USERPROFILE;localAppData=$local packageIdentity=[CompanionInstallerInventory]::CurrentPackage();signedInUser=(Get-CimInstance Win32_ComputerSystem).UserName;ancestry=$ancestry;explorer=$explorer baselineProducts=$baseline;candidateProducts=$current;family=$family;registration=$registration;installedFiles=$files;appsUseLightTheme=$theme word=@(Get-Process WINWORD -ErrorAction SilentlyContinue | Select-Object Id,SessionId,Path) agent=@(Get-Process PlotDirector.Companion.Agent -ErrorAction SilentlyContinue | Select-Object Id,SessionId,Path) stateDirectoryExists=Test-Path (Join-Path $local 'PlotDirector\Companion');backupDirectoryExists=Test-Path (Join-Path $local 'PlotDirector\InstallerBackup') startupShortcutExists=Test-Path (Join-Path ([Environment]::GetFolderPath('Startup')) 'PlotDirector Companion.lnk') menuShortcutExists=Test-Path (Join-Path ([Environment]::GetFolderPath('Programs')) 'PlotDirector Companion\PlotDirector Companion.lnk') } $snapshot | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $OutputPath -Encoding UTF8