Skip to content

Commit

Permalink
Add help, check for updates, version
Browse files Browse the repository at this point in the history
  • Loading branch information
asheroto committed Jun 20, 2023
1 parent 8a16ef2 commit 6af1696
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
44 changes: 44 additions & 0 deletions UninstallTeams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,40 @@ Describe "Get-ChatWidgetStatus Function" {
Remove-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Windows Chat" -Name "ChatIcon" -Force
}
}

Context "When -AllUsers switch is used without -EnableChatWidget, -DisableChatWidget, or -UnsetChatWidget" {
It "Should not throw an error" {
{ Get-ChatWidgetStatus -AllUsers } | Should -Not -Throw
}
}

Context "When -AllUsers switch is used with -EnableChatWidget" {
It "Should set the Chat widget status for all users" {
Set-ChatWidgetStatus -EnableChatWidget -AllUsers
$status = Get-ChatWidgetStatus -AllUsers
$status | Should -Be "Enabled"
# Disable the Chat widget for all users
Set-ChatWidgetStatus -DisableChatWidget -AllUsers
}
}

Context "When -AllUsers switch is used with -DisableChatWidget" {
It "Should set the Chat widget status for all users" {
Set-ChatWidgetStatus -DisableChatWidget -AllUsers
$status = Get-ChatWidgetStatus -AllUsers
$status | Should -Be "Disabled"
# Enable the Chat widget for all users
Set-ChatWidgetStatus -EnableChatWidget -AllUsers
}
}

Context "When -AllUsers switch is used with -UnsetChatWidget" {
It "Should set the Chat widget status for all users" {
Set-ChatWidgetStatus -UnsetChatWidget -AllUsers
$status = Get-ChatWidgetStatus -AllUsers
$status | Should -Be "Not Set"
}
}
}

Describe "Set-ChatWidgetStatus Function" {
Expand Down Expand Up @@ -90,4 +124,14 @@ Describe "Set-ChatWidgetStatus Function" {
$status | Should -Be "Not Set"
}
}

Context "When -AllUsers switch is used" {
It "Should set the Chat widget status for all users" {
Set-ChatWidgetStatus -EnableChatWidget -AllUsers
$status = Get-ChatWidgetStatus -AllUsers
$status | Should -Be "Enabled"
# Disable the Chat widget for all users
Set-ChatWidgetStatus -DisableChatWidget -AllUsers
}
}
}
61 changes: 52 additions & 9 deletions UninstallTeams.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ param (
[switch]$DisableChatWidget,
[switch]$UnsetChatWidget,
[switch]$AllUsers,
[switch]$Version
[switch]$Version,
[switch]$Help,
[switch]$CheckForUpdates
)

# Version
$CurrentVersion = '1.0.0'

# Check if -Version is specified
if ($Version.IsPresent) {
$CurrentVersion
exit 0
}

function Get-ChatWidgetStatus {
param (
[switch]$AllUsers
Expand Down Expand Up @@ -153,12 +164,45 @@ function Set-ChatWidgetStatus {
Write-Output "Chat widget has been $WhatChanged for $AllUsersString."
}

# Version
$MyVersion = '1.0.0'
function Check-GitHubRelease {
param (
[string]$Owner,
[string]$Repo
)
try {
$url = "https://api.github.com/repos/$Owner/$Repo/releases/latest"
$response = Invoke-RestMethod -Uri $url -ErrorAction Stop

# Check if -Version is specified
if ($Version.IsPresent) {
$MyVersion
$latestVersion = $response.tag_name
$publishedAt = $response.published_at

[PSCustomObject]@{
LatestVersion = $latestVersion
PublishedAt = $publishedAt
}
} catch {
Write-Error "Unable to check for updates. Error: $_"
exit 1
}
}

# Help
if ($Help) {
Get-Help -Name $MyInvocation.MyCommand.Source -Full
exit 0
}

# Check for updates
if ($CheckForUpdates) {
$Data = Check-GitHubRelease
$LatestVersion = $Data.LatestVersion
$PublishedAt = $Data.PublishedAt

if ($LatestVersion -gt $CurrentVersion) {
Write-Output "A new version of UninstallTeams is available. Current version: $CurrentVersion. Latest version: $LatestVersion. Published at: $PublishedAt."
} else {
Write-Output "UninstallTeams is up to date. Current version: $CurrentVersion. Latest version: $LatestVersion. Published at: $PublishedAt."
}
exit 0
}

Expand All @@ -184,9 +228,8 @@ try {
Write-Output ""

# Update note
$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptVersion = (Get-Command $ScriptPath).FileVersionInfo.ProductVersion
Write-Output "The current version of this script is $ScriptVersion. To update to the latest version, run 'Update-Script UninstallTeams -Force'."
Write-Output "Uninstall Teams $ScriptVersion"
Write-Output "To check for updates, run UninstallTeams -CheckForUpdates"

# Spacer
Write-Output ""
Expand Down

0 comments on commit 6af1696

Please sign in to comment.