Uninstall-SecureMFAEmailOtpProvider.ps1

<#
     .SYNOPSIS
        Uninstall SecureMfaEmailOtpProvider authentication provider from ADFS server.
    .DESCRIPTION
        Completely remove SecureMfaEmailOtpProvider from all ADFS farm servers you need to run it on all ADFS nodes (not web application proxy servers).
        This command must be executed using elevated PowerShell command window on your federation server(s)
        If you are using federation server farm that uses Windows Internal Database, you must execute commands on the primary federation server first
 
    .PARAMETER Force
        Force parameter suspends prompt message.
 
    .NOTES
        Version: 1.0.1.2
        Author: SecureMfa.com
        Creation Date: 04/09/2019
        Purpose/Change: Incorporated into module
   
    .EXAMPLE
        C:\PS> Uninstall-SecureMfaEmailOtpProvider
 
        This command will uninstall SecureMfaEmailOtpProvider from a ADFS node.
 
    .EXAMPLE
        C:\PS> Uninstall-SecureMfaEmailOtpProvider -Force
          
        This command will uninstall SecureMfaEmailOtpProvider from a ADFS node without any prompts.
#>


$dllpath = (Join-Path -Path $PSScriptRoot -ChildPath SecureMfaEmailOtpProvider.dll)
#Spanish language
$dllpath_es = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\es\SecureMfaEmailOtpProvider.resources.dll')                  
#French language
$dllpath_fr = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\fr\SecureMfaEmailOtpProvider.resources.dll')  
#German language
$dllpath_de = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\de\SecureMfaEmailOtpProvider.resources.dll')
#Chinese language
$dllpath_zh = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\zh\SecureMfaEmailOtpProvider.resources.dll')  
#Portuguese language
$dllpath_pt = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\pt\SecureMfaEmailOtpProvider.resources.dll')
#Russian language
$dllpath_ru = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\ru\SecureMfaEmailOtpProvider.resources.dll') 
#Italian language
$dllpath_it = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\it\SecureMfaEmailOtpProvider.resources.dll') 
#Arabic language
$dllpath_ar = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\ar\SecureMfaEmailOtpProvider.resources.dll') 
#Turkish language
$dllpath_tr = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\tr\SecureMfaEmailOtpProvider.resources.dll')
#Dutch language
$dllpath_nl = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\nl\SecureMfaEmailOtpProvider.resources.dll')  
#Finnish language
$dllpath_fi = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\fi\SecureMfaEmailOtpProvider.resources.dll')
#Swedish language
$dllpath_sv = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\sv\SecureMfaEmailOtpProvider.resources.dll') 
#Norwegian language
$dllpath_no = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\no\SecureMfaEmailOtpProvider.resources.dll') 
#Polish language
$dllpath_pl = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\pl\SecureMfaEmailOtpProvider.resources.dll') 
#Danish language
$dllpath_da = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\da\SecureMfaEmailOtpProvider.resources.dll')
#Lithuanian language
$dllpath_lt = (Join-Path -Path $PSScriptRoot -ChildPath 'Languages\lt\SecureMfaEmailOtpProvider.resources.dll')   

$languages_array = @(("Spanish", $dllpath_es),("French", $dllpath_fr),("German", $dllpath_de),("Chinese", $dllpath_zh),("Portuguese", $dllpath_pt),("Russian", $dllpath_ru),("Italian", $dllpath_it),("Arabic", $dllpath_ar),("Turkish", $dllpath_tr),("Dutch", $dllpath_nl),("Finnish", $dllpath_fi),("Swedish", $dllpath_sv),("Norwegian", $dllpath_no),("Polish", $dllpath_pl),("Danish", $dllpath_da),("Lithuanian", $dllpath_lt))

#Check if windows events source for application log exist, if not create one.
if ([System.Diagnostics.EventLog]::SourceExists("Secure MFA Email OTP") -eq $False) {New-EventLog -LogName "Application" -Source "Secure MFA Email OTP"}


Function Uninstall-SecureMFAEmailOtpProvider {
Param
(
    [Parameter(Mandatory=$false, ParameterSetName="Default")]
    [Switch]$Force
)

    #Confirm unisntall
    $message  = "Do you want to uninstall SecureMfaEmailOtpProvider from $env:computername ?"            
    $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'))
    if(!($force)) {$decision_option = $Host.UI.PromptForChoice($message, $question, $choices, 0)}

    if ($decision_option -eq 0 -or $Force) 
        {
        try
        {
        $Error.Clear()
        if (!(Test-Path $dllpath -Type Leaf) ) { throw "The assembly $dllpath does not exist" }
        
        Write-Host "Removing SecureMfaEmailOtpProvider from $env:computername" -ForegroundColor Yellow 

        #Remove additional authentication providers from ADFS global policy and unregister SecureMfaEmailOtpProvider
        Set-AdfsGlobalAuthenticationPolicy -AdditionalAuthenticationProvider ""
        unregister-AdfsAuthenticationProvider -Name �SecureMfaEmailOtpProvider� -Confirm:$false

        #Restart ADFS service
        write-host "Restarting adfssrv service." -ForegroundColor Green
        Stop-Service adfssrv
        Start-Service adfssrv

        #Load GAC Assembly
        write-host "Removing files from GAC Assembly." -ForegroundColor Green
        Set-location $PSScriptRoot           
        [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") 
        $publish = New-Object System.EnterpriseServices.Internal.Publish 

        #Remove SecureMfaEmailOtpProvider Languages DLL files from GAC assembly
        $languages_array | % { 
                       Write-Host "Removing language" $_[0] ":" $_[1]  -ForegroundColor yellow;
                       $publish.GacRemove($_[1])
                             }

        #Remove SecureMfaEmailOtpProvider DLL from GAC assembly
        Write-Host "Removing SecureMfaEmailOtpProvider $dllpath" -ForegroundColor yellow;
        $publish.GacRemove($dllpath) 
        
        }
        catch
        {
            Write-Host "$($MyInvocation.InvocationName): $_" -ForegroundColor red
        }     

        } 
    else {Write-Host "Skiping SecureMfaEmailOtpProvider unistall from $env:computername" -ForegroundColor Yellow }     

}