Public/Disable-InternetExplorer.ps1

function Disable-InternetExplorer {
    <#
    .SYNOPSIS
        Disables Internet Explorer as a Windows optional feature.
    .DESCRIPTION
        Removes Internet Explorer from the system by disabling the
        internet-explorer-optional-amd64 Windows optional feature. A system restart may be
        required depending on whether any IE components are in use at the time of removal.
    .INPUTS
        None. Parameters must be supplied directly.
    .OUTPUTS
        None.
    .PARAMETER ComputerName
        The target computer. Defaults to the local machine.
    .PARAMETER Force
        Restarts the computer immediately if the operation indicates a restart is needed.
    .EXAMPLE
        Disable-InternetExplorer

        Disables Internet Explorer on the local machine.
    .EXAMPLE
        Disable-InternetExplorer -ComputerName 'Workstation01' -Force

        Disables Internet Explorer on Workstation01 and restarts it if required.
    .NOTES
        Requires Administrator privileges.
        Remote operations require WinRM to be configured on the target machine.
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    [OutputType([void])]

    param (
        [Parameter(Mandatory = $false)]
        [string]$ComputerName = $env:COMPUTERNAME,

        [Parameter(Mandatory = $false)]
        [switch]$Force
    )

    $isLocal = ($ComputerName -ieq $env:COMPUTERNAME) -or
               ($ComputerName -ieq 'localhost') -or
               ($ComputerName -eq '127.0.0.1')

    if ($PSCmdlet.ShouldProcess($ComputerName, 'Disable Windows optional feature: internet-explorer-optional-amd64')) {
        if ($isLocal) {
            $result = Disable-WindowsOptionalFeature -Online -FeatureName 'internet-explorer-optional-amd64' -NoRestart -ErrorAction Stop
            Write-Verbose "Internet Explorer disabled on '$ComputerName'."
            if ($result.RestartNeeded) {
                Write-Warning "A system restart is required for changes to take effect."
                if ($Force -and $PSCmdlet.ShouldProcess($ComputerName, 'Restart computer to apply changes')) {
                    Restart-Computer -ComputerName $ComputerName -Force
                }
            }
        } else {
            $restartNeeded = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
                $result = Disable-WindowsOptionalFeature -Online -FeatureName 'internet-explorer-optional-amd64' -NoRestart -ErrorAction Stop
                $result.RestartNeeded
            }
            Write-Verbose "Internet Explorer disabled on '$ComputerName'."
            if ($restartNeeded) {
                Write-Warning "A system restart is required for changes to take effect."
                if ($Force -and $PSCmdlet.ShouldProcess($ComputerName, 'Restart computer to apply changes')) {
                    Restart-Computer -ComputerName $ComputerName -Force
                }
            }
        }
    }
}