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.
LVL 17
Alex Green3rd Line Server SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
For one, you could refactor the repeating code blocks with a function and a loop
0
Alex Green3rd Line Server SupportAuthor Commented:
That's not a bad shout actually, so would it work doing something like a Hash table and then have a foreach for that?
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
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
0
Do You Have a Trusted Wireless Environment?

A Trusted Wireless Environment is a framework for building a complete Wi-Fi network that is fast, easy to manage, and secure.

Alex Green3rd Line Server SupportAuthor Commented:
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.
0
oBdACommented:
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

1
Alex Green3rd Line Server SupportAuthor Commented:
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
0
ste5anSenior DeveloperCommented:
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.
0
oBdACommented:
The batch from above translated to PowerShell:
$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


ste5an,
Win32_Product should be avoided. This is not a simple query, it initiates a consistency check of packages installed, verifying and repairing the install!
Event log message indicates that the Windows Installer reconfigured all installed applications
https://support.microsoft.com/en-us/help/974524/event-log-message-indicates-that-the-windows-installer-reconfigured-al
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alex Green3rd Line Server SupportAuthor Commented:
Thanks all :D
0
oBdACommented:
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

1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.