Avatar of Alex
Alex
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Installing via powershell

@ECHO OFF

setlocal enabledelayedexpansion

::: Find 8x8 v5.1.0.18959
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{DDF96E66-E39B-4A69-B776-2DE49EBCAFBD}\" /s >NUL 2>&1 | FIND "DisplayVersionVersion=5.1.0.18959"
	IF %ErrorLevel% EQU 0 (
Goto :5.1.0.18959Uninstall
)

::: Uninstall
:5.1.0.18959Uninstall 
MsiExec.exe /X{DDF96E66-E39B-4A69-B776-2DE49EBCAFBD} /qn 2> NUL

::: Find 8x8 v5.2.0.19289
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{D7D3F00A-638B-41DE-A2A3-FFC6EF034783}\" /s >NUL 2>&1 | FIND "DisplayVersion=5.2.0.19289" > NUL 2> NUL
	IF %ErrorLevel% EQU 0 (
Goto :5.2.0.19289Uninstall
)

::: Uninstall
:5.2.0.19289Uninstall 
MsiExec.exe /X{D7D3F00A-638B-41DE-A2A3-FFC6EF034783} /qn 2> NUL

::: Find 8x8 v5.3.1.19599
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{B1A6CB20-C032-4228-940F-AC3BC9BF6B3E}\" /s >NUL 2>&1 | FIND "DisplayVersion=5.3.1.19599" > NUL 2> NUL
	IF %ErrorLevel% EQU 0 (
Goto :5.3.1.19599Uninstall
)

::: Uninstall 
:5.3.1.19599Uninstall 
MsiExec.exe /X{B1A6CB20-C032-4228-940F-AC3BC9BF6B3E} /qn 2> NUL

::: Find 8x8 v5.4.0.19820
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33}\" /s >NUL 2>&1 | FIND "DisplayVersion=5.4.0.19820" > NUL 2> NUL
	IF %ErrorLevel% EQU 0 (
Goto :5.4.0.19820Uninstall
)

::: Uninstall 
:5.4.0.19820Uninstall 
MsiExec.exe /X{3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33} /qn 2> NUL

::: Find 8x8 v5.5.0.19923
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{D8A08493-2F06-4EB2-A636-4392991981AB}\" /s >NUL 2>&1 | FIND "DisplayVersion=5.5.0.19923" > NUL 2> NUL
	IF %ErrorLevel% EQU 0 (
Goto :5.5.0.19923Uninstall
)

::: Uninstall 
:5.5.0.19923Uninstall 
MsiExec.exe /X{D8A08493-2F06-4EB2-A636-4392991981AB} /qn 2> NUL

:::8x8 VOD Latest Version Installation
:Install8x8
::: Copy the latest version of the VOD to the path below and change the msi filename
msiexec /i \\Domain\SYSVOL\DOmain\scripts\8x8\VOD_5_5_0.msi /qn

Open in new window



I'd be interested to know if there is an easier or better way to do this in powershell.
Powershell

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon
Shaun Vermaak

For one, you could refactor the repeating code blocks with a function and a loop
Alex

ASKER
That's not a bad shout actually, so would it work doing something like a Hash table and then have a foreach for that?
Shaun Vermaak

Correct. Especially the Uninstall/Find part. If there is other logic behind which applications those GUIDs belong to, you might even drop the GUID from the script and do a lookup by text (display name) and get the GUID at runtime.

This way it can support multiple versions
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Alex

ASKER
Excellent, let me bash something together and I'll report back, thank you for the ideas, I knew it could be done, I just needed to know the best way to achieve it.
oBdA

That batch script will fail all over the place, sorry.
The "DisplayVersionVersion" in line 6 aside:
- You're suppressing the standard output of reg.exe, so find.exe will never find anything.
- You have a "goto" in the "if", but no "else" section, so the script will always process all uninstall commands.
- msiexec.exe is a GUI application, not a command line tool, so it needs to be called using "start /wait", otherwise control will be returned to the script as soon as msiexec is started, without waiting for msiexec to finish.
That can certainly be done in PowerShell, but it's actually just a few basic commands in batch:
@echo off
setlocal enabledelayedexpansion

set GUIDs=DDF96E66-E39B-4A69-B776-2DE49EBCAFBD D7D3F00A-638B-41DE-A2A3-FFC6EF034783 B1A6CB20-C032-4228-940F-AC3BC9BF6B3E 3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33 D8A08493-2F06-4EB2-A636-4392991981AB
for %%a in (%GUIDs%) do (
	reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{%%a}" >NUL 2>&1
	if not errorlevel 1 (
		echo Uninstalling %%a
		start "Uninstalling %%a" /wait msiexec.exe /X{%%a} /qn
	)
)

:::8x8 VOD Latest Version Installation
::: Copy the latest version of the VOD to the path below and change the msi filename
start "Installing VOD" /wait msiexec.exe /i \\Domain\SYSVOL\DOmain\scripts\8x8\VOD_5_5_0.msi /qn

Open in new window

Alex

ASKER
oBdA

This isn't my code, I've been asked to fix it :D, I'm shocking with Batch and they asked to fit it into a powershell script.

But i'll give that a shot now.

Thanks
Alex
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ste5an

Reading the registry: Working with Registry Keys. Then you can call MsiExec using Start-Process:

$result = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/X$Guid" -Wait -Passthru).ExitCode

Open in new window

Just complete the skeleton:

Function Uninstall () {
    Param ( [string] $Guid, [string] $DisplayVersion )
    # TODO: Read registry into $RegistryVersion.
    If ($DisplayVersion -eq $RegistryVersion) {
      # TODO: Call MsiExec.
    }
}

Uninstall Guid="{DDF96E66-E39B-4A69-B776-2DE49EBCAFBD}" DisplayVersion="5.1.0.18959"
Uninstall Guid="{D7D3F00A-638B-41DE-A2A3-FFC6EF034783}" DisplayVersion="5.2.0.19289" 
Uninstall Guid="{B1A6CB20-C032-4228-940F-AC3BC9BF6B3E}" DisplayVersion="5.3.1.19599" 
Uninstall Guid="{3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33}" DisplayVersion="5.4.0.19820" 
Uninstall Guid="{D8A08493-2F06-4EB2-A636-4392991981AB}" DisplayVersion="5.5.0.19923"  

Open in new window

Normal programs are removed by querying WMI like

$program = Get-WmiObject -Class Win32_Product | 
    Where-Object {  $_.Name -match "Software Name" }
$program.Uninstall()

Open in new window

So maybe you can query your applications also.
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Alex

ASKER
Thanks all :D
oBdA

Just noticed an error, sorry; line 11 and 12 need to be swapped, in case you haven't noticed it yet (that is, the msiexec call needs to be inside the "If" statement):
$guids = @(
	'DDF96E66-E39B-4A69-B776-2DE49EBCAFBD'
	'D7D3F00A-638B-41DE-A2A3-FFC6EF034783'
	'B1A6CB20-C032-4228-940F-AC3BC9BF6B3E'
	'3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33'
	'D8A08493-2F06-4EB2-A636-4392991981AB'
)
ForEach ($guid In $guids) {
	If (Get-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{$guid}" -ErrorAction SilentlyContinue) {
		Write-Host "Uninstalling $($guid)"
		& msiexec.exe /X{$guid} /qn | Out-Null
	}
}
Write-Host "Installing VOD"
& msiexec.exe /i \\Domain\SYSVOL\DOmain\scripts\8x8\VOD_5_5_0.msi /qn | Out-Null 

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck