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.
Error:
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:
function Do-UploadReport {
param (
(String)
$FileName,
(String)
$FileType,
(String)
$WONum
)
$url = "http://URL/$WONum"
sleep 2
get-process iexplore 2> $null | stop-process 2> $null
try
{
$ie = New-Object -com InternetExplorer.Application
}
catch
{
Write-Output "Script Failed, please re-try, report error accordingly."
Write-Host $_
Pause
Exit
}
$ie.TheaterMode = $True
$ie.visible = $true
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate($ie.Name)
Start-Sleep -Milliseconds 500
$ie.navigate($url)
While ($ie.Busy -eq $true) {Start-Sleep -Milliseconds 1000}
$link = $ie.Document.getElementById("file")
Do-WindowsFileDiagSelection
$link.Click()
sleep 1
$wshell.SendKeys('^f')
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
$wshell.SendKeys('{TAB}')
sleep 1
$wshell.SendKeys('{ENTER}')
If ($FileType -eq "WORKSHEET") {sleep 15}
If ($FileType -eq "CLIENT_FILE") {sleep 35}
If ($FileType -eq "SUBMITTAL") {sleep 50}
$ie.TheaterMode = $False
}