Skip to content

Commit

Permalink
Improve DisableOfficeTeamsInstall
Browse files Browse the repository at this point in the history
- Adding registry key if it doesn't exist.
  • Loading branch information
asheroto committed Aug 30, 2023
1 parent c3286e8 commit 2343879
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions UninstallTeams.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#PSScriptInfo
.VERSION 1.1.1
.VERSION 1.1.2
.GUID 75abbb52-e359-4945-81f6-3fdb711239a9
.AUTHOR asherto
.COMPANYNAME asheroto
Expand All @@ -22,6 +22,7 @@
[Version 1.0.5] - Changed -CheckForUpdates to -CheckForUpdate.
[Version 1.1.0] - Various bug fixes. Added removal of Desktop and Start Menu shortcuts. Added method to prevent Office from installing Teams. Added folders and registry keys to detect.
[Version 1.1.1] - Improved Chat widget warning detection. Improved output into section headers.
[Version 1.1.2] - Improved DisableOfficeTeamsInstall by adding registry key if it doesn't exist.
#>

<#
Expand Down Expand Up @@ -91,7 +92,7 @@ UninstallTeams -UnsetOfficeTeamsInstall
Removes the Office Teams registry value, effectively enabling it since that is the default.
.NOTES
Version : 1.1.1
Version : 1.1.2
Created by : asheroto
.LINK
Expand All @@ -115,7 +116,7 @@ param (
)

# Version
$CurrentVersion = '1.1.1'
$CurrentVersion = '1.1.2'
$RepoOwner = 'asheroto'
$RepoName = 'UninstallTeams'
$PowerShellGalleryName = 'UninstallTeams'
Expand Down Expand Up @@ -313,30 +314,22 @@ function Set-OfficeTeamsInstallStatus {
[switch]$UnsetOfficeTeamsInstall
)

# According to Microsoft, HKLM is the only key that matters for this (no HKCU)
$RegistryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Office\16.0\Common\OfficeUpdate"

if (-Not (Test-Path $RegistryPath)) {
Write-Output "Creating registry path $RegistryPath."
New-Item -Path $RegistryPath -Force | Out-Null
}

if ($EnableOfficeTeamsInstall) {
$WhatChanged = "enabled"
if (Test-Path $RegistryPath) {
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 0 -Type DWord -Force
} else {
New-Item -Path $RegistryPath | Out-Null
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 0 -Type DWord -Force
}
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 0 -Type DWord -Force
} elseif ($DisableOfficeTeamsInstall) {
$WhatChanged = "disabled"
if (Test-Path $RegistryPath) {
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 1 -Type DWord -Force
} else {
New-Item -Path $RegistryPath | Out-Null
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 1 -Type DWord -Force
}
Set-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -Value 1 -Type DWord -Force
} elseif ($UnsetOfficeTeamsInstall) {
$WhatChanged = "unset (default is enabled)"
if (Test-Path $RegistryPath) {
Remove-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -ErrorAction SilentlyContinue
}
Remove-ItemProperty -Path $RegistryPath -Name "PreventTeamsInstall" -ErrorAction SilentlyContinue
}

Write-Output "Office's ability to install Teams has been $WhatChanged."
Expand Down

0 comments on commit 2343879

Please sign in to comment.