Is there a foolproof way for the script to wait till the Internet explorer is completely loaded?
Both oIE.Busy and / or oIE.ReadyState are
try to put this script on the top, this may solve Your problem.
{
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
if ($myWindowsPrincipal.IsInRole($adminRole)) {
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
Clear-Host;
}
else {
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
$newProcess.Verb = "runas";
[System.Diagnostics.Process]::Start($newProcess);
Exit;
}
}
Explanation:
Powershell is not having some rights when you are running script from the normal mode so it is not reading IE status properly and that is why DOM is not being loaded so, script doesn't found any parameter