Modules/APSUpdater/apsupdater.psm1
<# .SYNOPSIS Updates APS. .DESCRIPTION Downloads and installs the latest APS from the PowerShell Gallery. .PARAMETER Force Forces the command to run without asking for user confirmation. .PARAMETER KeepPreviousVersion Determines whether to keep the previous version. By default, it is removed. .EXAMPLE Update-APS #> function Update-APS{ [CmdletBinding(SupportsShouldProcess, HelpUri="https://github.com/akotu235/APS/blob/master/Docs/Modules/APSUpdater/Update-APS.md")] param( [switch]$Force, [switch]$KeepPreviousVersion ) $APS_Module = Get-Module APS $currentVersionNumber = Get-APSCurrentVersion $moduleBase = "$($APS_Module.ModuleBase)\..\$($currentVersionNumber.ToString())" if(($APS_Module.Version) -lt $currentVersionNumber -or $Force){ Update-Module APS -Force:$Force -Confirm:$false if(-not $KeepPreviousVersion){ Get-ChildItem "$moduleBase\.." | ForEach-Object { if(($currentVersionNumber.ToString()) -notlike $_){ Remove-Item ($_.FullName) -Recurse -Force } } } Get-ChildItem -Path $moduleBase -Recurse | Where-Object -Property Extension -Match ".psm?1" | ForEach-Object { $content = Get-Content -Path $_.FullName $content | ForEach-Object {$_.replace('`n','`r`n')} Set-Content -Path $_.FullName -Value $content } Remove-Module -Name APS -Force -ErrorAction SilentlyContinue (Get-ChildItem "$moduleBase\Modules").Name | ForEach-Object {Remove-Module -Name $_ -Force -ErrorAction SilentlyContinue } Import-Module APS } else{ Write-Host "APS is up to date" -ForegroundColor DarkGreen } } <# .SYNOPSIS Gets the latest APS version number from the PowerShell Gallery. #> function Get-APSCurrentVersion{ $url = "https://www.powershellgallery.com/packages/APS/?dummy=$(Get-Random)" $request = [System.Net.WebRequest]::Create($url) $request.AllowAutoRedirect=$false try{ $response = $request.GetResponse() $version = $response.GetResponseHeader("Location").Split("/")[-1] -as [Version] $response.Close() $response.Dispose() return $version } catch { Write-Warning $_.Exception.Message } } # SIG # Begin signature block # MIIIWAYJKoZIhvcNAQcCoIIISTCCCEUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZM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ulg # zCOJ1VhBHbaWGobDR9otmqxfabFKKjjOAI9iN26OpHv4rjRGHNgnX9fy465DARde # M6EstKS8WBmm1WM+4n72dzZFEn+CQ9n3fzY9SfKb6FXrnIwbgfvSQJJ0YDW2yvLT # Hk79nIxLKDZibLKeLCfpVG4mSsEhMk1BioE5OlKt7FFHWsIES5B/mDyAhB7saZfM # +jksJjGn0nawWBOYMss3KFP/ODHA0XJwYKNAU4GRS91oIOsin0+ssKYvklqLqKKu # 86huodEco0tNfcAAwFkbuR5hV19ohxd1ZRHebqQOcPmrnPQCA/heX9lgMTN8S3ha # +YAriZecILa3wMO4ZI4UQVzWCUt9+rBTq5LZLjbvXBYm0N9j2ZohHjPVYFNo0Fmw # i7o9Du927YcnwWq5ULNVM0vvTxCH54/yDK1LJDA8QsPHRa7IztR5SwN6XJeOMREY # kW6DLacmu5pXe43iRhEsz6m1PY6j2WDalucU/JonjmpBoD3aEdDIkuYlZAJZkfRI # DS0Uf+O0aKVQzZCFEps5Ajlkk7q5kGBenQxHBmqYDVl2u6KVNFE8Zu7kQ5q0SL49 # XGE4vz4+BwRT70UL9sRcb/qiMIgn8/x0HaHAmieUUXhWDbKlRJDsTOmZ7Lh2/inF # wXPaouGcVKxgURmGyCS1U6yrXl0uwhbbf1Kf9g== # SIG # End signature block |