Uninstall-SecureMfaOtpProvider.ps1

<#
     .SYNOPSIS
        Uninstall SecureMfaOtpProvider authentication provider from ADFS server.
    .DESCRIPTION
        Completely remove SecureMfaOtpProvider 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.7
        Author: SecureMfa.com
        Creation Date: 03/09/2019
        Purpose/Change: Incorporated into PS module
   
    .EXAMPLE
        C:\PS> Uninstall-SecureMfaOtpProvider
 
        This command will uninstall SecureMfaOtpProvider from a ADFS node.
 
    .EXAMPLE
        C:\PS> Uninstall-SecureMfaOtpProvider -Force
          
        This command will uninstall SecureMfaOtpProvider from a ADFS node without any prompts.
#>


$dllpath = (Join-Path -Path $PSScriptRoot -ChildPath SecureMfaOtpProvider.dll)

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

#Check if ADFS service is available
if((Get-Service adfssrv -ErrorAction SilentlyContinue).Status -eq "Stopped") {Start-Service adfssrv ; write-host "Starting ADFS Service on $env:COMPUTERNAME" -ForegroundColor Yellow;}

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

    #Confirm unisntall
    $message  = "Do you want to uninstall SecureMfaOtpProvider 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 SecureMfaOtpProvider from $env:computername" -ForegroundColor Yellow 

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

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

            #Load GAC Assembly
            write-host "Removing 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 SecureMfaOtpProvider 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 SecureMfaOtpProvider unistall from $env:computername" -ForegroundColor Yellow }     

}