ps/Modules/Alkami.PowerShell.IIS/Public/Uninstall-WebExtension.ps1

96 lines
2.7 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
Function Uninstall-WebExtension {
<#
.SYNOPSIS
Uninstall a WebExtension from the appropriate place.
.DESCRIPTION
Uninstall a WebExtension from the appropriate place.
Will make certain assumptions based on best practices, such as locations to install to based on flags.
.PARAMETER ExtensionName
[string] The name of the extension. Will be used to build a dynamic path. Typically the package id.
.PARAMETER IsAdmin
[switch] Is this package installed to admin?
.PARAMETER RemoveLogs
[switch] Remove logs if the service was running?
.INPUTS
ExtensionName is required.
.OUTPUTS
Various diagnostic information about the uninstall process
.EXAMPLE
Uninstall-WebExtension -ExtensionName Alkami.Client.WebExtension.Example -SourcePath C:\ProgramData\chocolatey\lib\Alkami.Client.WebExtension.Example
Various diagnostic information about the uninstall process.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, Position=0)]
[string]$ExtensionName,
[switch]$isAdmin,
[switch]$RemoveLogs
)
process {
$loglead = (Get-LogLeadName)
if (!(Test-IsDeveloperMachine) -and !(Test-IsWebServer)) {
Write-Warning "$loglead : Can not install WebExtensions on the app tier"
return
}
if (!(Test-IsAdmin)){
throw "You are not running as administrator. Can not continue."
}
$appName = 'WebClient'
if ($isAdmin) {
$appName = 'WebClientAdmin'
}
$orbExtensionPath = (Join-Path (Join-Path (Join-Path (Get-OrbPath) $appName) 'Modules') $ExtensionName)
$isRunning = (Test-IISAppPoolByName $appName)
if ($isRunning) {
Write-Host "$loglead : Stopping $appName"
Stop-WebAppPool $appName
Do
{
Start-Sleep -Milliseconds 100
}
Until ((Get-WebAppPoolState -Name $appName).Value -eq "Stopped" )
}
if ($RemoveLogs) {
$logfiles = Get-LogPathsForOrbApplication $appName
foreach($logPath in $logfiles) {
if (Test-Path $logPath) {
Remove-FileSystemItem $logPath -ErrorAction Stop
}
}
}
## Clear .NET Temp files associated with the site
$tempFilePath = (Get-SiteTempDirectoryPath $appName)
if ($isRunning -and !([string]::IsNullOrWhiteSpace($tempFilePath)) -and (Test-Path $tempFilePath)) {
Remove-FileSystemItem $tempFilePath -Recurse -ErrorAction Stop
}
if (Test-Path $orbExtensionPath) {
## Update OrbCore manifest if it exists to say that I've removed these files from the folder
Remove-FileSystemItem $orbExtensionPath -Recurse -ErrorAction Stop
}
if ($isRunning) {
Write-Host "$loglead : Starting $appName"
Start-WebAppPool $appName
}
}
}