Public/Enable-InternetExplorer.ps1

function Enable-InternetExplorer {
    <#
    .SYNOPSIS
        Enables Internet Explorer as a Windows optional feature.
    .DESCRIPTION
        Restores Internet Explorer by enabling the internet-explorer-optional-amd64 Windows
        optional feature. A system restart may be required depending on the current state of
        the feature installation.
    .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
        Enable-InternetExplorer

        Enables Internet Explorer on the local machine.
    .EXAMPLE
        Enable-InternetExplorer -ComputerName 'Workstation01' -Force

        Enables 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 = 'Medium')]
    [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, 'Enable Windows optional feature: internet-explorer-optional-amd64')) {
        if ($isLocal) {
            $result = Enable-WindowsOptionalFeature -Online -FeatureName 'internet-explorer-optional-amd64' -NoRestart -ErrorAction Stop
            Write-Verbose "Internet Explorer enabled 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 = Enable-WindowsOptionalFeature -Online -FeatureName 'internet-explorer-optional-amd64' -NoRestart -ErrorAction Stop
                $result.RestartNeeded
            }
            Write-Verbose "Internet Explorer enabled 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
                }
            }
        }
    }
}