UpdateTeams.ps1


<#PSScriptInfo

.VERSION 1.0.1

.GUID c2a51a32-766b-4fa3-8912-5dea2caef931

.AUTHOR Fabrice Sanga

.COMPANYNAME sangafabrice

.COPYRIGHT © 2022 SangaFabrice. All rights reserved.

.TAGS teams nuget-package update communication

.LICENSEURI https://github.com/sangafabrice/reg-cli/blob/main/LICENSE.md

.PROJECTURI https://github.com/sangafabrice/reg-cli/tree/teams

.ICONURI https://rawcdn.githack.com/sangafabrice/reg-cli/fb13d0066e1b7bdfe7059e93926ab8e85ade2482/icon.png

.EXTERNALMODULEDEPENDENCIES DownloadInfo,RegCli

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
Add common script to updater script.

.PRIVATEDATA

#>


#Requires -Module @{ModuleVersion = '5.0.4'; ModuleName = 'DownloadInfo'}
#Requires -Module @{ModuleVersion = '6.2.2'; ModuleName = 'RegCli'}

[CmdletBinding()]
Param (
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallLocation $_ $PSScriptRoot })]
    [string]
    $InstallLocation = "${Env:ProgramData}\Teams",
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallerLocation $_ })]
    [string]
    $SaveTo = $PSScriptRoot
)

& {
    $NameLocation = "$InstallLocation\Teams.exe"
    Try {
        $UpdateModule =
            Import-CommonScript chrome-installer |
            Import-Module -PassThru -Force -Verbose:$False
        @{
            UpdateInfo = $(
                Write-Verbose 'Retrieve install or update information...'
                Try {
                    Get-DownloadInfo -PropertyList @{
                        OSArch = Get-ExecutableType $NameLocation
                    } -From Teams
                }
                Catch { }
            )
            NameLocation = $NameLocation
            SaveTo = $SaveTo
            SoftwareName = 'Microsoft Teams'
            InstallerType = 'Squirrel'
            Verbose = $VerbosePreference -ine 'SilentlyContinue'
        } | ForEach-Object { Invoke-CommonScript @_ }
    }
    Catch { }
    Finally { $UpdateModule | Remove-Module -Verbose:$False }
}

<#
.SYNOPSIS
    Updates Microsoft Teams software.
.DESCRIPTION
    The script installs or updates Microsoft Teams on Windows.
.NOTES
    Required: at least Powershell Core 7.
.PARAMETER InstallLocation
    Path to the installation directory.
    It is restricted to file system paths.
    It does not necessary exists.
    It defaults to %ProgramData%\Teams.
.PARAMETER SaveTo
    Path to the directory of the downloaded installer.
    It is an existing file system path.
    It defaults to the script directory.
.EXAMPLE
    Get-ChildItem C:\ProgramData\Teams -ErrorAction SilentlyContinue

    PS > .\UpdateTeams.ps1 -InstallLocation C:\ProgramData\Teams -SaveTo .

    PS > Get-ChildItem C:\ProgramData\Teams | Select-Object Name -First 5
    Name
    ----
    locales
    resources
    swiftshader
    api-ms-win-core-console-l1-1-0.dll
    api-ms-win-core-console-l1-2-0.dll

    PS > Get-ChildItem | Select-Object Name
    Name
    ----
    microsoft_teams_1.5.0.21668.exe
    UpdateTeams.ps1

    Install Teams to 'C:\ProgramData\Teams' and save its setup installer to the current directory.
#>