$ie = New-Object -com internetexplorer.application
$ie.navigate("<https://example.com/download-page>")
while ($ie.busy) { Start-Sleep -Milliseconds 100 }
$downloadButton = $ie.Document.getElementsByTagName("button") | where-object {$_.value -eq "Download"}
$downloadButton.click()
while ($ie.busy) { Start-Sleep -Milliseconds 100 }
while ($ie.Document.getElementsByTagName("body").innerText -notmatch "Do you want to save the file?") { Start-Sleep -Milliseconds 100 }
$confirmationDialog = $ie.Document.parentWindow.confirmDialog
$savePath = "C:\\Users\\username\\Downloads\\file-to-download"
$confirmationDialog.Accept()
$ie.Document.IHTMLDocument2_execCommand("SaveAs", $false, $savePath)
while (!(Test-Path $savePath)) { Start-Sleep -Milliseconds 100 }
$ie.Quit()