From 03bfcadfb82e59fccee8517f49ddfa62a985646e Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Mon, 15 Jul 2024 14:48:39 -0700 Subject: [PATCH] Apps reports Version and Publisher correctly and Uninstall Programs works --- Private/Apps.ps1 | 6 +++--- Private/SCCMQuery.ps1 | 4 ++-- Private/UninstallProgram.ps1 | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Private/UninstallProgram.ps1 diff --git a/Private/Apps.ps1 b/Private/Apps.ps1 index fe6c95c..fa19a5e 100644 --- a/Private/Apps.ps1 +++ b/Private/Apps.ps1 @@ -3,16 +3,16 @@ $86apps, $64apps = Get-SCCM_Apps $ComputerName #Checks if local computer - if ($comp -eq $env:COMPUTERNAME) { + if ($ComputerName -eq $env:COMPUTERNAME) { $localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller | - Select-Object @{N='DisplayName';E={$_.Name}} | + Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } else { #Checks if pc is online so Invoke doesn't hang on offline pc if (Test-Connection -ComputerName $ComputerName -Count 1) { $localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock { Get-Package -ProviderName Programs -IncludeWindowsInstaller | - Select-Object @{N='DisplayName';E={$_.Name}} | + Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } } diff --git a/Private/SCCMQuery.ps1 b/Private/SCCMQuery.ps1 index 29240a2..7d8b55c 100644 --- a/Private/SCCMQuery.ps1 +++ b/Private/SCCMQuery.ps1 @@ -442,10 +442,10 @@ function Get-SCCM_Apps($ComputerName) { SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'" $64apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX64Query | - Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName + Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName $86apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX86Query | - Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName + Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName return $86apps, $64apps } diff --git a/Private/UninstallProgram.ps1 b/Private/UninstallProgram.ps1 new file mode 100644 index 0000000..0cf92eb --- /dev/null +++ b/Private/UninstallProgram.ps1 @@ -0,0 +1,34 @@ +function Invoke-UninstallProgram ($Computer) { + Invoke-Command -ComputerName $Computer -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock { + $target = Read-Host "Name of app to uninstall" + $apps = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -match $target} + if (-not ($apps -is [array])) { + $apps = @($apps) + } + if ($apps.Length -eq 0) { + Write-Host -ForegroundColor Red "No app matching '$target' found on $Computer" + return + } + for ($i=0; $i -lt $apps.Length; $i++) { + Write-Host "[$i] $($apps[$i].Name)" + } + $selection = Read-Host "Which app(s) do you want to uninstall?" + if (-not ($selection)) { return } + $selection = -split $selection + foreach ($item in $selection) { + Write-Host "[$item] $($apps[$item].Name)" + } + $res = Read-Host "Are you sure you want to delete this/these app(s)?" + if (-not ($res -match "^[yY]")) { + Write-Host -ForegroundColor Red "Uninstall Aborted" + return + } + foreach ($item in $selection) { + Write-Host "Uninstalling $($apps[$item].Name)" + $res = $apps[$item].Uninstall() + if ($res.ReturnValue) { + Write-Warning "$appname failed to uninstall from $Computer with ReturnValue $($res.ReturnValue)" + } + } + } +}