We help IT Professionals succeed at work.

Installing via powershell

Alex
Alex asked
on
78 Views
1 Endorsement
Last Modified: 2018-09-04
@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.
Comment
Watch Question

Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
For one, you could refactor the repeating code blocks with a function and a loop
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

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?
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
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
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

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.
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
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

AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

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
ste5anSenior Developer
CERTIFIED EXPERT

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
Thanks all :D
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.