Uninstall-SecureMfaThreatDetectionModule.ps1
<#
.SYNOPSIS Uninstall SecureMfaThreatDetectionModule authentication provider from ADFS server. .DESCRIPTION Completely remove SecureMfaThreatDetectionModule 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: 2.0.0.4 Author: SecureMfa.com Creation Date: 02/08/2021 Purpose/Change: Incorporated into PS module .EXAMPLE C:\PS> Uninstall-SecureMfaThreatDetectionModule This command will uninstall SecureMfaThreatDetectionModule from a ADFS node. .EXAMPLE C:\PS> Uninstall-SecureMfaThreatDetectionModule -Force This command will uninstall SecureMfaThreatDetectionModule from a ADFS node without any prompts. #> $dllpath = (Join-Path -Path $PSScriptRoot -ChildPath SecureMfaThreatDetectionModule.dll) #Check if windows events source for application log exist, if not create one. if ([System.Diagnostics.EventLog]::SourceExists("Secure MFA TDM") -eq $False) {New-EventLog -LogName "Application" -Source "Secure MFA TDM"; Write-Host "Secure MFA TDM 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-SecureMfaThreatDetectionModule { Param ( [Parameter(Mandatory=$false, ParameterSetName="Default")] [Switch]$Force ) #Confirm unisntall $message = "Do you want to uninstall SecureMfaThreatDetectionModule 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 SecureMfaThreatDetectionModule from $env:computername" -ForegroundColor Yellow #Unregister SecureMfaThreatDetectionModule from ADFS UnRegister-AdfsThreatDetectionModule -Name "SecureMfaThreatDetectionModule" #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 SecureMfaThreatDetectionModule DLL from GAC assembly Write-Host "Removing SecureMfaThreatDetectionModule $dllpath" -ForegroundColor yellow; $publish.GacRemove($dllpath) } catch { Write-Host "$($MyInvocation.InvocationName): $_" -ForegroundColor red } } else {Write-Host "Skiping SecureMfaThreatDetectionModule unistall from $env:computername" -ForegroundColor Yellow } } |