Skip to content

Instantly share code, notes, and snippets.

@MyITGuy
Last active November 1, 2023 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MyITGuy/2caaab08447a45403e85155ede845005 to your computer and use it in GitHub Desktop.
Save MyITGuy/2caaab08447a45403e85155ede845005 to your computer and use it in GitHub Desktop.
1612 - The installation source for this product is not available. Verify that the source exists and that you can access it. Error 1612 may be produced during a repair or uninstall of a Windows Installer product. In some environments, files in the '$
#region Get-WILocalPackages
function Get-WILocalPackages {
[CmdletBinding()]
PARAM(
[Parameter(Mandatory = $false)]
[switch]
$Audit
,
[Parameter(Mandatory = $false)]
[string[]]
$ComputerName = $env:COMPUTERNAME
)
begin {
Write-Verbose $MyInvocation.MyCommand
Write-Verbose "ComputerName: $ComputerName"
}
process {
foreach ($ComputerNameEx In $ComputerName) {
try {
$Properties = @{
ComputerName = $ComputerNameEx
Found = $null
NotFound = $null
FoundSize = $null
FolderSize = $null
}
try {
if (@('.', 'localhost', $env:COMPUTERNAME) -notcontains $Properties.ComputerName) {
Write-Verbose "Remote computer"
$key = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Properties.ComputerName)
}
else {
Write-Verbose "Local computer"
$key = [Microsoft.Win32.Registry]::LocalMachine
}
$LocalPackages = @()
$Products = $key.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products', $false)
$LocalPackages += ForEach ($SubKeyName In $Products.GetSubKeyNames()) {
try {
$subkey = $Products.OpenSubKey($SubKeyName)
$InstallProperties = $subkey.OpenSubKey('InstallProperties')
$InstallProperties.GetValue('LocalPackage') | Select-Object -Property @{Name="LocalPackage";Expression={$_}}
}
catch {
}
}
$Patches = $key.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Patches', $false)
$LocalPackages += ForEach ($SubKeyName In $Patches.GetSubKeyNames()) {
try {
$subkey = $Products.OpenSubKey($SubKeyName)
$subkey.GetValue('LocalPackage') | Select-Object -Property @{Name = "LocalPackage"; Expression = {$_}}
}
catch {
}
}
$LocalPackages = $LocalPackages | Where-Object { $_.LocalPackage } | ForEach-Object {
if (@('.', 'localhost', $env:COMPUTERNAME) -notcontains $Properties.ComputerName) {
$_.LocalPackage = "\\$($Properties.ComputerName)\$($_.LocalPackage -replace ':', '$')"
$_
}
else {
$_
}
}
$LocalPackages | ForEach-Object {
$_ | Add-Member -MemberType NoteProperty -Name "FileExist" -Value (Test-Path -Path $_.LocalPackage -PathType Leaf)
$_ | Add-Member -MemberType NoteProperty -Name "Length" -Value ((Get-Item -Path $_.LocalPackage -ErrorAction SilentlyContinue).Length)
}
$Properties.Found = ($LocalPackages | Where-Object { $_.FileExist -eq $true } | Measure-Object).Count
$Properties.NotFound = ($LocalPackages | Where-Object { $_.FileExist -eq $false } | Measure-Object).Count
$Properties.FoundSize = ($LocalPackages | Measure-Object -Sum Length | Select-Object -ExpandProperty Sum)
if (@('.', 'localhost', $env:COMPUTERNAME) -notcontains $Properties.ComputerName) {
$System32 = (Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $Properties.ComputerName).SystemDirectory
$Windir = Split-Path -Path $System32
$InstallerDir = Join-Path -Path $Windir -ChildPath "Installer"
$RemoteInstallerDir = $InstallerDir -replace ':', '$'
$Path = "\\$($Properties.ComputerName)\$($RemoteInstallerDir)"
Write-Verbose "Remote Installer Directory: $Path"
$Properties.FolderSize = (Get-ChildItem -Path $Path -Force | Measure-Object -Sum Length | Select-Object -ExpandProperty Sum)
}
else {
$Properties.FolderSize = (Get-ChildItem -Path $env:WINDIR\Installer -Force | Measure-Object -Sum Length | Select-Object -ExpandProperty Sum)
}
}
catch {
Write-Verbose $_.Exception.Message
}
if ($Audit) {
$obj = New-Object -TypeName PSObject -Property $Properties
Write-Output -InputObject $obj
}
else {
$LocalPackages
}
}
catch {
Throw $_
}
}
}
end {
}
}
#endregion Get-WILocalPackages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment