Uninstall-SecureMFA_WEPAPI_Portal.ps1
#Requires -RunAsAdministrator #Requires -Version 5.0 <# .SYNOPSIS Uninstalls SecureMFA WEB API Portalr. .DESCRIPTION Uninstalls SecureMFA WEB API Portal from Windows Server. .NOTES Version: 2.0.0.1 Author: SecureMfa.com Creation Date: 28/08/2020 Purpose/Change: Release .EXAMPLE C:\PS> Uninstall-SecureMFA_WEPAPI_Portal This command will Uninstalls SecureMFA WEB API Portal from Windows Server. #> Function Uninstall-SecureMFA_WEPAPI_Portal { Param ( [Parameter(Mandatory=$false)][string]$siteName = "SecureMFAWebAPI", [Parameter(Mandatory=$false)][string]$WebAPIPortalPath = "C:\inetpub\SecureMFAWebAPI\", [Parameter(Mandatory=$false)][string]$IISAppPoolName = "SecureMFAWebAPI", [Parameter(Mandatory=$false)][Switch]$Force ) #Validate uninsatall action if (!$Force) { $message = "Please confirm if you want to uninstall WEB API Portal [Web site $siteName will be deleted from $WebAPIPortalPath ]" $question = 'Please confirm?' $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes')) $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No')) $decision_Validation = $Host.UI.PromptForChoice($message, $question, $choices, 0) if ($decision_Validation -eq 1 ) {Write-Host "Uninstall has been cancelled, exiting!" -ForegroundColor Yellow ; break} } try { $Error.Clear() #Start Uninstall #Site Configuration Import-Module WebAdministration #Remove web site $site = Get-Website -Name $siteName if(!$site) {Write-Host "Site $siteName could not be found, Skipping ..."} else {Write-Host "Removing Web Site $siteName" -ForegroundColor Yellow ; Remove-WebSite -Name $siteName} #Remove IIS app pool if (Test-Path ("IIS:\AppPools\" + $IISAppPoolName)) { Write-Host "Removing App pool $IISAppPoolName" -ForegroundColor Yellow ; Remove-WebAppPool -Name $IISAppPoolName } else { Write-Host "$IISAppPoolName IIS AppPool does not exists. Skipping ..." } #Delete WEB API portal if(!(Test-Path ($WebAPIPortalPath))){Write-Host "Folder $WebAPIPortalPath could not be found, Skipping ..."} else {write-host "Removing $WebAPIPortalPath" -ForegroundColor Yellow ; Remove-Item $WebAPIPortalPath -Recurse -Force } # Uninstall completed: write-host "Uninstall of Site: $siteName ($WebAPIPortalPath) complete." -ForegroundColor Green } catch { Write-Host "$($MyInvocation.InvocationName): $_" -ForegroundColor red } } |