Upload files to "Reinstall Scripts"

This commit is contained in:
2025-08-09 16:33:34 +00:00
parent e6cc4a3725
commit fa334a4518
@@ -0,0 +1,132 @@
<#
Author: Gabe Kerntke
Date: 03-06-2024
.Synopsis
.Modified
2024-03-06 (GabeK) - Original script created
2025-08-09 (GabeK) - Updated to use functions script
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
$App_Name = "Teams",
[Parameter(Mandatory = $false)]
$File_Name_Extension = "exe",
[Parameter(Mandatory = $false)]
$Install_Parameters = "-p" ,
[Parameter(Mandatory = $false)]
$EPCache_Folder = "3rd Party Patches\$App_Name",
[Parameter(Mandatory = $false)]
$File_Name = "$App_Name.$File_Name_Extension",
[Parameter(Mandatory = $false)]
$users = (Get-ChildItem -path c:\users).name,
[Parameter(Mandatory = $false)]
$CurrentUser = ((get-ciminstance win32_computersystem | ForEach-Object username) -split '\\')[1]
)
$initialURL = "https://learn.microsoft.com/en-us/microsoftteams/new-teams-bulk-install-client"
# Download the HTML content
$html = (New-Object System.Net.WebClient).DownloadString("$initialURL")
# Split the content on ">" and "<" characters to extract the text content
$text = $html.Split([char[]]@(">", "<"), [StringSplitOptions]::RemoveEmptyEntries)
# Sort the start and end index of the page
$startIndex = $text.IndexOf("Option 1A: Download and install new Teams for a single computer")
$endIndex = $text.IndexOf("Option 1B: Download and install new Teams using an offline installer")
# Extract the rows
$rows = $text[$startIndex..$endIndex]
# Filter out only the rows containing version numbers
$Sort = $rows | Where-Object { $_ -match "https" }
$Split = $Sort.split() | Select-Object -First 2 | Select-Object -Last 1
$DownloadURL = $Split.Substring(5) -replace '"', ""
#Region Functions
Function Uninstall-Teams {
Stop-Process -name *teams* -Force -ErrorAction SilentlyContinue -Verbose
Start-Sleep 10
$Uninstall = Get-WmiObject Win32_Product -filter "name like 'Teams%'" | ForEach-Object { $_.Uninstall() }
$Value = $Uninstall | Select-Object -ExpandProperty ReturnValue
If ($Value -eq "0") {
Write-Host "$App_Name uninstalled successfully, proceeding to deleting user's appdata folders"
DeleteTeamsFolder
}
else {
Uninstall-Teams2
}
}
Function Uninstall-Teams2 {
$UninstallPath = $Applist | Select-Object -ExpandProperty PSPath
$B = $UninstallPath -replace "Microsoft.PowerShell.Core", ""
$C = $B.Substring(1)
Remove-Item -Path $C -Force -Verbose
Start-Sleep 5
If ($Applist.DisplayName -like "*$App_Name*") {
Write-Host "Failed to uninstall $App_Name, exiting script"
}
Else {
Write-Host "$App_Name uninstalled successfully, proceeding to deleting user's appdata folders"
DeleteTeamsFolder
}
}
Function DeleteTeamsFolder {
Get-AppxPackage -name *Teams* -AllUsers | Select-Object -ExpandProperty PackageFullName | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue -Verbose
$users = Get-ChildItem C:\Users
foreach ($user in $users) {
$path = "C:\Users\$($user.Name)\AppData\Local\Microsoft\Teams"
If (Test-Path $path) {
Remove-Item $path -Force -Recurse
Write-Output "$user Team's Appdata folder has been deleted, proceeding to install Teams"
}
}
Test-Probe_Online
Install-App
}
#Check to see if program is installed
Function CheckforClassicTeams {
$users = Get-ChildItem C:\Users
foreach ($user in $users) {
$Path = Test-Path "C:\Users\$($user.Name)\AppData\Local\Microsoft\Teams\current\Teams.exe"
If ($Path -eq $true) {
Stop-Process -name *teams* -Force -ErrorAction SilentlyContinue -Verbose
Start-Sleep 10
Write-Host "Teams Classic is installed for $user, proceeding with deleting user appdata folder"
DeleteTeamsFolder
}
Else {
Write-Host "Teams is not installed for $user, exiting script"
}
}
}
#Region Script Start
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Check if Teams Machine-Wide Installer is installed
$App_Name = "Teams Machine-Wide Installer"
$Applist = Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }
If ($Applist.DisplayName -like "*$App_Name*") {
Write-Host "$App_Name is already installed, proceeding with uninstall"
Close-App
Uninstall-Teams
}
Else {
Write-Host "$App_Name is not installed, proceeding to check under user's appdata folder for Classic Teams"
CheckforClassicTeams
}
#Region Script End