-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install-putty.ps1
56 lines (42 loc) · 1.84 KB
/
Install-putty.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.SYNOPSIS
Installation of putty
For Practice
.DESCRIPTION
Installs software in quite mode, creates logs
.OUTPUTS
Logs will be created in C:\ProgramData\quick\logs\$software
.NOTES
Version: 1.0
Author: CielGoldenflame
Creation Date: 2020 04 09
Purpose/Change: Test Script
.EXAMPLE
Run with ".\Install.ps1"
#>
# Define software name
$softwarename = "Putty"
# Logging Source Folder
$logroot = "$env:ProgramData\quick"
# define script source
$scripdir = Split-Path $Script:MyInvocation.MyCommand.Path
# Check for logging folder/create (logging is not vital for success)
if(Test-Path -Path "$logroot\$softwarename")
{
# Exists do nothing
}else{
#create path
New-Item -Path $logroot -Name $softwarename -ItemType Directory -Force -ErrorAction SilentlyContinue
}
# Var for all applications containing "putty*" gets Name and Uninstall string
$uninstallSoftware = Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall | `
Get-ItemProperty | Where-Object {$_.Displayname -like "*$softwarename*"} | Select-Object -Property Displayname, Uninstallstring
# loop through $uninstallsoftware
foreach($uninstallobject in $uninstallSoftware){
# remove msiexec /i & msiexec /x for uninstallstring
$uninstallobject.Uninstallstring = $uninstallobject.Uninstallstring -replace 'msiexec.exe /i', ""
$Uninstallstring = $uninstallobject.UninstallString -replace 'msiexec.exe /x', ""
Start-Process msiexec.exe -ArgumentList "/q /x $Uninstallstring /L $logroot\$softwarename\prev-ver-uninstall.log" -Wait
}
# Install command
Start-Process -FilePath $scripdir\putty-64bit-0.70-installer.msi -ArgumentList "/qn /norestart /l $logroot\$softwarename\install.log" -Wait