-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMultiMediaRedirection.ps1
More file actions
147 lines (115 loc) · 7.33 KB
/
MultiMediaRedirection.ps1
File metadata and controls
147 lines (115 loc) · 7.33 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
146
147
<#Author : Akash Chawla
# Usage : Install and enable multimedia redirection
#>
###########################################################
# Install and enable multimedia redirection #
###########################################################
[CmdletBinding()] Param (
[Parameter(
Mandatory
)]
[string]$VCRedistributableLink,
[Parameter(
Mandatory
)]
[string]$EnableEdge,
[Parameter(
Mandatory
)]
[string]$EnableChrome
)
function InstallAndEnableMMR($VCRedistributableLink, $EnableChrome, $EnableEdge) {
Begin {
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$templateFilePathFolder = "C:\AVDImage"
Write-host "Starting AVD AIB Customization: MultiMedia Redirection: $((Get-Date).ToUniversalTime()) "
$guid = [guid]::NewGuid().Guid
$tempFolder = (Join-Path -Path "C:\temp\" -ChildPath $guid)
if (!(Test-Path -Path $tempFolder)) {
New-Item -Path $tempFolder -ItemType Directory
}
$mmrHostUrl = "https://aka.ms/avdmmr/msi"
$mmrExePath = Join-Path -Path $tempFolder -ChildPath "mmrtool.msi"
}
Process {
try {
# Set reg key while the feature is in preview
New-Item -Path "HKLM:\SOFTWARE\Microsoft\MSRDC\Policies" -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSRDC\Policies" -Name ReleaseRing -PropertyType String -Value insider -Force
# Install the latest version of the Microsoft Visual C++ Redistributable
Write-host "AVD AIB Customization: MultiMedia Redirection - Starting the installation of provided Microsoft Visual C++ Redistributable"
$appName = 'mmr'
$drive = 'C:\'
New-Item -Path $drive -Name $appName -ItemType Directory -ErrorAction SilentlyContinue
$LocalPath = $drive + '\' + $appName
Set-Location $LocalPath
$VCRedistExe = 'vc_redist.x64.exe'
$outputPath = $LocalPath + '\' + $VCRedistExe
Invoke-WebRequest -Uri $VCRedistributableLink -OutFile $outputPath
Start-Process -FilePath $outputPath -Args "/install /quiet /norestart /log vcdist.log" -Wait -NoNewWindow
Write-host "AVD AIB Customization: MultiMedia Redirection - Finished the installation of provided Microsoft Visual C++ Redistributable"
#Install the host component
Write-host "AVD AIB Customization: MultiMedia Redirection - Starting the installation of host component"
Write-Host "AVD AIB Customization: MultiMedia Redirection - Downloading MMR host into folder $mmrExePath"
$mmrHostResponse = Invoke-WebRequest -Uri "$mmrHostUrl" -UseBasicParsing -UseDefaultCredentials -OutFile $mmrExePath -PassThru
if ($mmrHostResponse.StatusCode -ne 200) {
throw "MMR host failed to download -- Response $($mmrHostResponse.StatusCode) ($($mmrHostResponse.StatusDescription))"
}
$arguments = "/i `"$mmrExePath`" /quiet"
Start-Process msiexec.exe -ArgumentList $arguments -Wait -NoNewWindow
Write-Host "AVD AIB Customization: MultiMedia Redirection - Finished installing the mmr host agent"
#Enable Edge extension
if([System.Convert]::ToBoolean($EnableEdge)) {
Write-host "AVD AIB Customization: MultiMedia Redirection - Starting to enable extension for Microsoft Edge"
$registryValue = '{ "joeclbldhdmoijbaagobkhlpfjglcihd": { "installation_mode": "force_installed", "update_url": "https://edge.microsoft.com/extensionwebstorebase/v1/crx" } }';
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name ExtensionSettings -PropertyType String -Value $registryValue -Force
Write-host "AVD AIB Customization: MultiMedia Redirection - Finished enabling extension for Microsoft Edge"
}
if([System.Convert]::ToBoolean($EnableChrome)) {
#Install Chrome and enable extension
Write-host "AVD AIB Customization: MultiMedia Redirection - Checking if Google Chrome is installed"
try {
$chrome = $(Get-Package -Name "Google Chrome")
}
catch {
Write-host "AVD AIB Customization: MultiMedia Redirection - Google Chrome is not installed"
}
if([string]::IsNullOrEmpty($chrome)) {
Write-host "AVD AIB Customization: MultiMedia Redirection - Installing latest version of chrome"
$chromeInstallerPath = Join-Path -Path $tempFolder -ChildPath "chromeInstaller.exe"
$chromeResponse = Invoke-WebRequest "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -UseBasicParsing -UseDefaultCredentials -OutFile $chromeInstallerPath -PassThru
if ($chromeResponse.StatusCode -ne 200) {
throw "Google chrome failed to download -- Response $($chromeResponse.StatusCode) ($($chromeResponse.StatusDescription))"
}
Start-Process -FilePath $chromeInstallerPath -Args "/silent /install" -Verb RunAs -Wait
Write-host "AVD AIB Customization: MultiMedia Redirection - Finished installing Google Chrome"
}
$registryValue = '{ "lfmemoeeciijgkjkgbgikoonlkabmlno": { "installation_mode": "force_installed", "update_url": "https://clients2.google.com/service/update2/crx" } }';
New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -Name ExtensionSettings -PropertyType String -Value $registryValue -Force
Write-host "AVD AIB Customization: MultiMedia Redirection - Finished enabling extension for Google Chrome"
}
}
catch {
Write-Host "*** AVD AIB CUSTOMIZER PHASE *** MultiMedia Redirection - Exception occured *** : [$($_.Exception.Message)]"
}
}
End {
#Cleanup
if ((Test-Path -Path $templateFilePathFolder -ErrorAction SilentlyContinue)) {
Remove-Item -Path $templateFilePathFolder -Force -Recurse -ErrorAction Continue
}
if ((Test-Path -Path $tempFolder -ErrorAction SilentlyContinue)) {
Remove-Item -Path $tempFolder -Force -Recurse -ErrorAction Continue
}
$stopwatch.Stop()
$elapsedTime = $stopwatch.Elapsed
Write-Host "*** AVD AIB CUSTOMIZER PHASE : MultiMedia Redirection - Exit Code: $LASTEXITCODE ***"
Write-Host "Ending AVD AIB Customization : MultiMedia Redirection - Time taken: $elapsedTime"
}
}
InstallAndEnableMMR -VCRedistributableLink $VCRedistributableLink -EnableChrome $EnableChrome -EnableEdge $EnableEdge
#############
# END #
#############