PowerShell Fails to Create COM Instance of Internet Explorer after multiple successful runs

I made a function to upload documents and it worked great for a few months, then suddenly I was getting errors relating to failing to create the COM component. It sometimes will run 50x successfully, sometimes, just 5 or 6 times. I added a “catch” statement along with a forceful kill of all IE processes, but can’t get around the error and it’s driving me mad! Any suggestions? See Function Below.


Script Failed, please re-try, report error accordingly. Creating an
instance of the COM component with CLSID
{0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed
due to the following error: 800706bf The remote procedure call failed
and did not execute. (Exception from HRESULT: 0x800706BF). Press Enter
to continue…:


function Do-UploadReport {
    param (
    $url = "http://URL/$WONum"
    sleep 2
    get-process iexplore 2> $null | stop-process 2> $null
        $ie = New-Object -com InternetExplorer.Application
        Write-Output "Script Failed, please re-try, report error accordingly."
        Write-Host $_
    $ie.TheaterMode = $True
    $ie.visible = $true
    $wshell = New-Object -ComObject wscript.shell;
    Start-Sleep -Milliseconds 500
    While ($ie.Busy -eq $true) {Start-Sleep -Milliseconds 1000}
    $link = $ie.Document.getElementById("file")
    sleep 1
    sleep 1
    $wshell.SendKeys('Upload a File')
    sleep 1 
    $wshell.SendKeys('{TAB}{TAB}{TAB}{TAB}{TAB}') #On Report Type Selector
    sleep 1
    If ($FileType -eq "WORKSHEET") {$wshell.SendKeys('{DOWN}')}
    If ($FileType -eq "CLIENT_FILE") {$wshell.SendKeys('{UP}')}
    sleep 1
    sleep 1
    If ($FileType -eq "WORKSHEET") {sleep 15}
    If ($FileType -eq "CLIENT_FILE") {sleep 35}
    If ($FileType -eq "SUBMITTAL") {sleep 50}
    $ie.TheaterMode = $False