-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-Latest-rdpwrap.ps1
More file actions
146 lines (112 loc) · 3.91 KB
/
Install-Latest-rdpwrap.ps1
File metadata and controls
146 lines (112 loc) · 3.91 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<#
.SYNOPSIS
Downloads the latest sebaxakerhtc/rdpwrap installers from GitHub.
.DESCRIPTION
Downloads the latest sebaxakerhtc/rdpwrap installers from GitHub
and copies them into the "C:\Program Files\RDP Wrapper" folder
and executes the installer.
If Windows Defender is enabled, "C:\Program Files\RDP Wrapper"
will be added to the exclusions list.
.NOTES
Author: Jonathan Panning <jpann [at] impostr-labs.com>
Filename: Get-Latest-rdpwrap.ps1
Created on: 11-21-2023
Last updated: 01-04-2024
.PARAMETER OutPath
String. The path to download to.
.INPUTS
None.
.OUTPUTS
None. Get-Latest-rdpwrap.ps1 does not generate any output.
.EXAMPLE
PS> .\Get-Latest-rdpwrap.ps1
.LINK
https://github.com/jpann
#>
#requires -RunAsAdministrator
#requires -version 4
[CmdletBinding()]
Param()
BEGIN {
function Get-Latest-Version {
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Url
)
Write-Verbose "URL: $Url"
$tag = (Invoke-WebRequest -UseBasicParsing $Url| ConvertFrom-Json)[0].tag_name
$tagUrl = (Invoke-WebRequest -UseBasicParsing $Url| ConvertFrom-Json)[0].html_url
Write-Verbose "Tag URL: $tagUrl"
$tag
}
function Get-Latest-Assets {
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Url
)
$assetsObject = (Invoke-WebRequest -UseBasicParsing $Url| ConvertFrom-Json)[0].assets
$assets = @( )
foreach ($asset in $assetsObject) {
$assetName = $asset.name
$assetUrl = $asset.browser_download_url
$assets += @{
Name = $assetName;
Url = $assetUrl
}
}
$assets
}
function Download {
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Url,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$File
)
Write-Verbose "File: $File"
Write-Verbose "URL: $Url"
Invoke-WebRequest -Method Get -Uri:$Url -OutFile $File
}
$Script:REPO = "sebaxakerhtc/rdpwrap"
$Script:RELEASES = "https://api.github.com/repos/$Script:REPO/releases/latest"
$Script:RDPWrapperPath = "C:\Program Files\RDP Wrapper"
# Create RDP Wrapper path early so we can add it to the Windows Security Exclusions
if (-not(Test-Path -Path $Script:RDPWrapperPath -PathType Container)) {
Write-Host "Creating $($Script:RDPWrapperPath) ..."
New-Item $Script:RDPWrapperPath -Type Directory -Force | Out-Null
}
}
PROCESS {
$winSecurityEnabled = (Get-MpComputerStatus).AntivirusEnabled
if ($winSecurityEnabled) {
Write-Host "Adding $($Script:RDPWrapperPath) to Windows Security Exclusions ..."
Add-MpPreference -ExclusionPath $Script:RDPWrapperPath
}
Write-Host "Determining latest release ..."
$tag = Get-Latest-Version -Url $Script:RELEASES
Write-Host "Latest release is " -NoNewLine
Write-Host "$tag" -ForegroundColor Green
$assets = Get-Latest-Assets -Url $Script:RELEASES
Write-Host "This release has " -NoNewLine
Write-Host "$($assets.Count)" -ForegroundColor Green -NoNewLine
Write-Host " files"
foreach($asset in $assets) {
$fileName = $asset.Name
$url = $asset.Url
$filePath = Join-Path $Script:RDPWrapperPath $fileName
Write-Host ">> Downloading $fileName to $($Script:RDPWrapperPath) ..."
Download -File $filePath -Url $url
}
# Launch installer
$installerPath = Join-Path $Script:RDPWrapperPath "RDPW_Installer.exe"
if (Test-Path -Path "$installerPath" -PathType Leaf) {
Write-Host "Launching installer $installerPath ..."
Start-Process $installerPath
} else {
Write-Error "Installer $installerPath does not exist!"
}
}