Private/Invoke-IEReset.ps1

function Invoke-IEReset {
    [CmdletBinding()]
    param (
        [switch]$AsCurrentUser
    )

    if ($AsCurrentUser) {
        # Display a message saying attempting to run the command as the current logged in user
        Write-Output "Trying to run repairs as the current logged in user"

        # Check if RunAsUser module is loaded and import if it isn't
        if (!(Get-Module -Name RunAsUser -ListAvailable)) {
            Write-Output "RunAsUser module is not installed. Installing now..."
            try {
                Install-Module -Name RunAsUser -Scope CurrentUser -Force -ErrorAction Stop
                Write-Output "RunAsUser module installed successfully."
            }
            catch {
                Write-Error "Failed to install RunAsUser module: $_"
            }
        } else {
            Write-Output "RunAsUser module is installed."
        }

        if(-Not (psexec -accepteula -nobanner)) {
            if(choco) {
                Write-Output "PSEXEC is not installed. Trying to install with chocolatey..."
                try {
                    choco install psexec -y
                } catch {
                    Write-Error "Failed to install PSEXEC with chocolatey: $_"
                }
            }
            else {
                Write-Warning "PSEXEC is not installed. Please install it with Chocolatey."
            }
        }
        else {
            # Display a message saying psexec is installed
            Write-Output "PSEXEC is installed."

            # Display a message saying attempting to run the command as the current logged in user
            Write-Output "Attempting to run the command as the current logged in user"
            psexec /i /s "powershell.exe" "Invoke-AsCurrentUser -Command `"RunDll32.exe InetCpl.cpl,ResetIEtoDefaults`""
        }        
    }
    else {
        Start-Process -FilePath "RunDll32.exe" -ArgumentList "InetCpl.cpl,ResetIEtoDefaults" -Verb RunAs
    }
}