96 lines
3.4 KiB
PowerShell
96 lines
3.4 KiB
PowerShell
|
Function Uninstall-Widget {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Uninstalls a Widget
|
|||
|
#>
|
|||
|
|
|||
|
[CmdletBinding()]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory=$true, Position=0)]
|
|||
|
[string]$WidgetName,
|
|||
|
[switch]$isAdmin,
|
|||
|
[switch]$RemoveLogs
|
|||
|
)
|
|||
|
process {
|
|||
|
$loglead = (Get-LogLeadName)
|
|||
|
|
|||
|
if (!(Test-IsDeveloperMachine) -and !(Test-IsWebServer)) {
|
|||
|
Write-Warning "$loglead : Can not install widgets on the app tier"
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!(Test-IsAdmin)){
|
|||
|
throw "You are not running as administrator. Can not continue."
|
|||
|
}
|
|||
|
|
|||
|
$appName = 'WebClient';
|
|||
|
|
|||
|
if ($isAdmin) {
|
|||
|
$appName = 'WebClientAdmin';
|
|||
|
Write-Information "$loglead : Widget uninstall against Admin does not remove the bins from the bin folder. Sorry for the inconvenience."
|
|||
|
Write-Information "$loglead : For more details, discuss with the tooling team. If you're *on the tooling team*, ask Cole or Bob."
|
|||
|
}
|
|||
|
|
|||
|
$orbAreaPath = (Join-Path (Join-Path (Join-Path (Get-OrbPath) $appName) 'Areas') $WidgetName)
|
|||
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Justification="Variable assignment is used if isAdmin=true. False positive.")]
|
|||
|
$orbAreaBinPath = (Join-Path $orbAreaPath "bin")
|
|||
|
|
|||
|
if ($isAdmin) {
|
|||
|
$orbAreaBinPath = (Join-Path (Join-Path (Get-OrbPath) $appName) "bin")
|
|||
|
}
|
|||
|
|
|||
|
## Get the IIS sites by path then get the distinct application pool names for all sites bound to this path.
|
|||
|
$orbBaseWebclientPath = Join-Path (Get-OrbPath) $appName
|
|||
|
Write-Verbose "$loglead : Orb Base webclient path [$orbBaseWebclientPath]"
|
|||
|
|
|||
|
$iisApplicationPools = @()
|
|||
|
$iisSites = (Get-IISSitesByPath $orbBaseWebclientPath)
|
|||
|
foreach($site in $iisSites) {
|
|||
|
if ($site.ApplicationPool -notin $iisApplicationPools) {
|
|||
|
$iisApplicationPools += $site.ApplicationPool
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
foreach($appPool in $iisApplicationPools) {
|
|||
|
$isRunning = (Test-IISAppPoolByName $appPool)
|
|||
|
if ($isRunning) {
|
|||
|
Write-Host "$loglead : Stopping $appPool"
|
|||
|
Stop-WebAppPool $appPool
|
|||
|
Do
|
|||
|
{
|
|||
|
Start-Sleep -Milliseconds 100;
|
|||
|
}
|
|||
|
Until ((Get-WebAppPoolState -Name $appPool).Value -eq "Stopped" )
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if ($RemoveLogs) {
|
|||
|
$logfiles = Get-LogPathsForOrbApplication $appName
|
|||
|
|
|||
|
$logfiles | ForEach-Object {
|
|||
|
$logPath = $_;
|
|||
|
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 $orbAreaPath) {
|
|||
|
## Update OrbCore manifest if it exists to say that I've removed these files from the folder
|
|||
|
Remove-FileSystemItem $orbAreaPath -Recurse -ErrorAction Stop
|
|||
|
}
|
|||
|
|
|||
|
foreach($appPool in $iisApplicationPools) {
|
|||
|
if ($isRunning) {
|
|||
|
Write-Host "$loglead : Starting $appPool"
|
|||
|
Start-WebAppPool $appPool
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|