How to automatically login to Chrome using PowerShell. I have a script that runs using IE but need to use Chrome

Viewed 2698

#Set URL.

$Url = "https://www.plexonline.com"; 
$Username="xxxx";
$Password="xxxx";
$CompanyCode="xxx";

Create a new COM object for IE.

$IE = New-Object -ComObject internetexplorer.application;

Set IE to FullScreen.

$IE.FullScreen = $true;

Set IE to visible.

$IE.Visible = $true;

Navigate IE to the specified URL.

$IE.navigate($url); 

Wait until IE is not longer busy.

 while ($IE.Busy -eq $true) 
    { 
        Start-Sleep -Milliseconds 500; 
    } 

Insert the specified username, password, and company code in to their respective fields.

$IE.Document.getElementById("txtUserID").value = $Username;
$IE.Document.getElementByID("txtPassword").value = $Password;
$IE.Document.getElementByID("txtCompanyCode").value = $CompanyCode;

Start the login process.

$IE.Document.getElementById("btnLogin_Label").Click();

Continue to wait until IE is no longer busy.

while ($IE.Busy -eq $true) 
{ 
Start-Sleep -Milliseconds 2000; 
}   
1 Answers

Unfortunately, Google doesn't support COM Model & thus hasn't provided COM Objects to be used in PowerShell.

However, you can use Start-Process to spin up a Google Chrome process, and then you can proceed with the rest of your steps accordingly:

$Url = "https://www.plexonline.com"; 
$Username="xxxx";
$Password="xxxx";

$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))

Start-Process "<path to chrome.exe>" $Url -Credential $Credential -WindowStyle Maximized
Related