Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Using Powersell to remove apps and reinstall newer versions of the same app

$
0
0

Forgive the way my mind wanders I am trying to automate removed a variable number of apps and reinstall the newer version of the same apps from a lot of Windows 7/10 computers I am not even sure it is possible.

 

I have only used PowerShell this week so my skills are below newbie level in it

I have to visit about 300 workstations each of them will have between 1 and 20 programs named RED XXXX

I am trying to write/modify a script to do the following

Make a list of all application named “RED”

Uninstall all applications whose name starts with RED

Reinstall the new version of the Red Application

I found and slightly edited this script which gets a list of most of the application and saves it

# back up list of currently installed RED and save to C:\IT\Red.txt

$app= Get-WmiObjectWin32_Product| where { $_.name-like"*Red*" } | Out-Filec:\it\Red.txt

 But it is not 100% correct it misses a few so I found this script

If(!([Diagnostics.Process]::GetCurrentProcess(). Path -match ‘\\syswow64\\’)) {

$unistallPath = “\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\”

$unistallWow6432Path = “\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\”

@( if (Test-Path “HKLM:$unistallWow6432Path” ) { Get-ChildItem “HKLM:$unistallWow6432Path”} if (Test-Path “HKLM:$unistallPath” ) { Get-ChildItem “HKLM:$unistallPath” } if (Test-Path “HKCU:$unistallWow6432Path”) { Get-ChildItem “HKCU:$unistallWow6432Path”} if (Test-Path “HKCU:$unistallPath” ) { Get-ChildItem “HKCU:$unistallPath” } ) | ForEach-Object { Get-ItemProperty $_.PSPath } | Where-Object { $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and !$_.ParentKeyName -and ($_.UninstallString -or $_.NoRemove) } | Sort-Object DisplayName | Select-Object DisplayName

}

else { -foregroundColor red

}  | Out-File C:\IT\red.txt

 

This one is accurate and complete but when I try to pipe the output I get an empty Pipe is not allowed error and it gives me all application not just the ones from Red

 

I need to combine the two, then I need to have the created file be the variable for the install part of the script

 

I found a new Script that also works

Get-Package -Provider Programs -IncludeWindowsInstaller -Name "Red*" | Out-File C:\it\Red.txt

This is the output

Red Apple           12.7.1501.2                                      Programs                                                                                                    

Red Sky                  12.4.20000.53                                    Programs                                                                                                    

Red Sand                 12.7.3031.3                                      Programs                                                                                                    

Red Planet               12.7.3030.2                                      Programs                                                                                                    

Red Carpet               12.7.1501.4                                      Programs

 

So I need to uninstall $red (pull list from c:\it\red.txt

Then I want to reinstall the newer version of the same programs

Like Install-Package –$red "K:\$red\red.exe" –force

But instead of using red I want powershell to use a variable and just reinstall the new versions of the same program it just deleted otherwise its 1hr per machine times about 300 machines.

The issue is each machine could have a different number or "Red" programs and or a different set of the 22 possible red programs. ie machine a1111 could have red moon but not red sky, A1112 could have red moon, red, sky, red sand, and a1113 could have all 22 Red programs installed.

 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>