I have the following block of code. I want to continue after running a function in the catch block. I know it’s not possible this way, I’m just wondering if there is a way to dot source or some other trick to make it work.
code:
Function Get-LatestEdgeWebDriver {
$modpath = (join-path -path ($env:PSModulePath -split ';')[0] -ChildPath 'Selenium3.0.1assemblies')
$filepath = Join-Path -Path $modpath -ChildPath 'edgedriver_win64.zip'
Set-Location $modpath
$EdgeExe = Get-ItemPropertyValue 'HKLM:SOFTWAREMicrosoftWindowsCurrentVersionApp Pathsmsedge.exe' "(default)"
$version = (Get-Item $EdgeExe).VersionInfo.ProductVersion
$download = 'https://msedgedriver.azureedge.net/' + $version + '/edgedriver_win64.zip'
$web_request = Invoke-WebRequest -Uri $download
if(($web_request.Content[0] -is [byte]) -and $web_request.StatusCode -eq 200){
if ($PSversiontable.psversion.major -eq 7) {
Set-Content -Path $filepath -asBytestream -Value $web_request.Content -ErrorAction SilentlyContinue -Force
} else {Set-Content -Path $filepath -Encoding Byte -Value $web_request.Content -ErrorAction SilentlyContinue -Force}
}
Load-Module '7Zip4Powershell'
Expand-7Zip -ArchiveFileName .edgedriver_win64.zip -TargetPath .
Start-Sleep -seconds 5
if((Get-Process | Where-Object {$_.Name -eq 'MicrosoftWebDriver'} | Measure-object).Count -gt 0)
{Get-Process -name MicrosoftWebDriver | kill -Force}
Move-Item -Path .msedgedriver.exe -Destination .MicrosoftWebDriver.exe -Force
Remove-Item -Path .edgedriver_win64.zip -Force -ErrorAction SilentlyContinue
Set-Location $scriptpath
write-host -ForegroundColor yellow "Edge Webdriver Updated to $version version.."
}
# Code starts here
# More code here
try {
$Driver = Start-SeEdge -StartURL $uri -PrivateBrowsing -Quiet -Minimized -WarningVariable $warn -WarningAction SilentlyContinue
Enter-SeUrl $uri -Driver $Driver -WarningAction SilentlyContinue
}catch {[System.Management.Automation.MethodInvocationException]{
write-host -ForegroundColor Yellow "Old version of Edgedriver found. updating... "
Get-LatestEdgeWebDriver
# Continue out of catch
}
}
# continue code below this line
1