Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell script for auto Gmail logon won't work on 2nd system

$
0
0

I run the following Powershell script to auto logon to a Gmail account on my first Windows 7 system and it works just fine:

# Ensure that you are not already signed-in Gmail!
#seeking help to improve this script

$url = "http://gmail.com"
$username="myname"
$password="mypassword"
#$ie = New-Object -com internetexplorer.application;
#$ie.visible = $true;
#$ie.navigate($url);
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true
$ie.navigate($url);
$sw = @'
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
'@

$type = Add-Type -Name ShowWindow2 -MemberDefinition $sw -Language CSharpVersion3 -Namespace Utils -PassThru
$type::ShowWindow($ie.hwnd, 3) # 3 = maximize
while ($ie.Busy -eq $true)
{
 Start-Sleep -Milliseconds 1000;
}
$ie.Document.getElementById("email").value = $username
$ie.Document.getElementByID("Passwd").value=$password
$ie.Document.getElementById("signin").Click();

The problem is I just got a second new Windows 7 system and when I attempt to run the very same auto logon to a Gmail account on that system, I get the following error message from Powershell:

PS C:\Windows\system32> D:\Hold\PowerShell\gmailautologon.ps1
24
Method invocation failed because [System.__ComObject] doesn't contain a method named 'getElementById'.
At D:\Hold\PowerShell\gmailautologon.ps1:24 char:28
+ $ie.Document.getElementById <<<< ("email").value = $username
    + CategoryInfo          : InvalidOperation: (getElementById:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.__ComObject] doesn't contain a method named 'getElementByID'.
At D:\Hold\PowerShell\gmailautologon.ps1:25 char:28
+ $ie.Document.getElementByID <<<< ("Passwd").value=$password
    + CategoryInfo          : InvalidOperation: (getElementByID:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.__ComObject] doesn't contain a method named 'getElementById'.
At D:\Hold\PowerShell\gmailautologon.ps1:26 char:28
+ $ie.Document.getElementById <<<< ("signin").Click();
    + CategoryInfo          : InvalidOperation: (getElementById:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

So my question is:

Why does my Powershell auto logon to a Gmail account work just fine on my first Windows 7 system, but fails on my new second Windows 7 system? 

Note: I'm no Powershell techie, so any help would be appreciated!

Thanks in advance!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>