TeamsOnWVD.psm1

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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
########## Teams for Windows Virtual Desktop
# Author : Yannick Dils
# Create Date : 09/04/2020
# Version : 2.0
##########

function install-teams64bit
{
#region step 1 - Import regkeys

Write-Host "Step 1 : Checking the required registry keyssn" -ForegroundColor Cyan


$KeyPath = "HKLM:\SOFTWARE\Microsoft\Teams\"
$WVDKey = "IsWVDEnvironment"

        IF(!(Test-Path $KeyPath))
            {
                Write-Host "The path does not exist, we will create this path now" -ForegroundColor red
                New-Item -Path $KeyPath -Force 
                New-ItemProperty -Path $KeyPath -Name $WVDKey -PropertyType "DWORD" -Value "1" -Force
            }
        else
            {
                Write-Host "The path already exists, we don't need to create this path now" -ForegroundColor Green
                New-ItemProperty -Path $KeyPath -Name $WVDKey -PropertyType "DWORD" -Value "1" -Force 
            }
#endregion step 1
#region step 2 - Download the Teams MSI Package


$DownloadLink = "https://statics.teams.cdn.office.net/production-windows-x64/1.3.00.4461/Teams_windows_x64.msi"
$TempDir = "C:\Temp"
$Output = "C:\Temp\teams64.msi"
$Logfile = $TempDir + "\logfile.txt"
$Path = Test-Path $TempDir

    If ($Path -eq $true)
        {
            Write-Host "Step 2 : The C:\Temp path already exists, no need to create one" -ForegroundColor Cyan
        }
    Else
        {
            Write-host "Step 2 : We are creating a temp directory C:\Temp" -ForegroundColor Cyan
            $DontShow = mkdir $TempDir
        }

(New-Object System.Net.WebClient).DownloadFile($DownloadLink, $output)
cd $TempDir
#endregion step 2
#region step 3 - Install Teams MSI

Write-Host "Step 3 : Let us install Teams" -ForegroundColor Cyan
msiexec /i $Output /l*v $Logfile ALLUSER=1 ALLUSERS=1

#endregion step 3
}

function install-teams32bit
{
#region step 1 - import regkeys

Write-Host "Step 1 : Let us first set a couple or registry keysn" -ForegroundColor Cyan

$KeyPath = "HKLM:\SOFTWARE\Microsoft\Teams\"
$WVDKey = "IsWVDEnvironment"

        IF(!(Test-Path $KeyPath))
            {
                Write-Host "The path does not exist, we will create this path now" -ForegroundColor red
                New-Item -Path $KeyPath -Force 
                New-ItemProperty -Path $KeyPath -Name $WVDKey -PropertyType "DWORD" -Value "1" -Force

            }
        else
            {
                Write-Host "The path already exists, we don't need to create this path now" -ForegroundColor Green
                New-ItemProperty -Path $KeyPath -Name "$WVDKey" -PropertyType "DWORD" -Value "1" -Force 
            }
#endregion step 1
#region step 2 - Download the Teams MSI Package


$DownloadLink = "https://statics.teams.cdn.office.net/production-windows/1.3.00.4461/Teams_windows.msi"
$TempDir = "C:\Temp"
$Output = "C:\Temp\teams32.msi"
$Logfile = $TempDir + "\logfile.txt"
$Path = Test-Path $TempDir

    If ($Path -eq $true)
        {
            Write-Host "Step 2 : The C:\Temp path already exists, no need to create one" -ForegroundColor Cyan
        }
    Else
        {
            Write-host "Step 2 : We are creating a temp directory C:\Temp" -ForegroundColor Cyan
            $DontShow = mkdir $TempDir
        }

(New-Object System.Net.WebClient).DownloadFile($DownloadLink, $output)
cd $TempDir
#endregion step 2
#region step 3 - Install Teams MSI

Write-Host "Step 3 : Let us install Teams" -ForegroundColor Cyan
msiexec /i $Output /l*v $Logfile ALLUSER=1 ALLUSERS=1

#endregion step 3
}

function remove-teams64bit
{
#region step 1 - Teams Per User Uninstall

Write-Host "Step 1 : Let us un-install Teams per user base" -ForegroundColor Cyan

Get-WmiObject -Class Win32_Product | Where-Object {$_.IdentifyingNumber -eq "{39AF0813-FA7B-4860-ADBE-93B9B214B914}"} | Remove-WmiObject
$ListUsers = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"

$ListUsers | ForEach-Object {
    Try { 
        if (Test-Path "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams") {
            Start-Process -FilePath "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams\Update.exe" -ArgumentList "-uninstall -s"
        }
    } Catch { 
        Out-Null
    }
}

$ListUsers | ForEach-Object {
    Try {
        if (Test-Path "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams") {
            Remove-Item â€“Path "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams" -Recurse -Force -ErrorAction Ignore
        }
    } Catch {
        Out-Null
    }
}
#endregion step 1
#region step 2 - Teams Machine Wide Uninstall
Write-Host "Step 2 : Let us un-install Teams per machine base" -ForegroundColor Cyan

#get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize
$TeamsWMI = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "Teams Machine-Wide Installer"} 
$TeamsGUID = $TeamsWMI.IdentifyingNumber
MsiExec.exe /X$TeamsGUID /qn 
$TeamsWMI | Remove-WmiObject
#endregion step 2 - Teams Machine Wide Uninstall
#region step 3 - Remove regkeys

Write-Host "Step 3 : Checking the required registry keyssn" -ForegroundColor Cyan


$KeyPath = "HKLM:\SOFTWARE\Microsoft\Teams\"
$WVDKey = "IsWVDEnvironment"

        IF(!(Test-Path $KeyPath))
            {
                Write-Host "The path does not exist, we don't have to remove it" -ForegroundColor red
                
            }
        else
            {
                Write-Host "The path exists, we will remove it now" -ForegroundColor Green
                Remove-Item -Path $KeyPath -Force 
                #Remove-ItemProperty -Path $KeyPath -Name $WVDKey -PropertyType "DWORD" -Value "1" -Force
            }
#endregion step 3


}