Apps reports Version and Publisher correctly and Uninstall Programs works
This commit is contained in:
parent
062f91059e
commit
03bfcadfb8
|
|
@ -3,16 +3,16 @@
|
||||||
$86apps, $64apps = Get-SCCM_Apps $ComputerName
|
$86apps, $64apps = Get-SCCM_Apps $ComputerName
|
||||||
|
|
||||||
#Checks if local computer
|
#Checks if local computer
|
||||||
if ($comp -eq $env:COMPUTERNAME) {
|
if ($ComputerName -eq $env:COMPUTERNAME) {
|
||||||
$localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
$localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
||||||
Select-Object @{N='DisplayName';E={$_.Name}} |
|
Select-Object @{N='DisplayName';E={$_.Name}},* |
|
||||||
Sort-Object -Property DisplayName
|
Sort-Object -Property DisplayName
|
||||||
} else {
|
} else {
|
||||||
#Checks if pc is online so Invoke doesn't hang on offline pc
|
#Checks if pc is online so Invoke doesn't hang on offline pc
|
||||||
if (Test-Connection -ComputerName $ComputerName -Count 1) {
|
if (Test-Connection -ComputerName $ComputerName -Count 1) {
|
||||||
$localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock {
|
$localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock {
|
||||||
Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
||||||
Select-Object @{N='DisplayName';E={$_.Name}} |
|
Select-Object @{N='DisplayName';E={$_.Name}},* |
|
||||||
Sort-Object -Property DisplayName
|
Sort-Object -Property DisplayName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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'"
|
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 |
|
$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 |
|
$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
|
return $86apps, $64apps
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
Private/UninstallProgram.ps1
Normal file
34
Private/UninstallProgram.ps1
Normal file
|
|
@ -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)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue