Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Powershell to open internet explorer and login into sharepoint

$url = "https://example.sharepoint.com/" 
$username="[email protected] " 
$password="Password" 


$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url);


while ($ie.Busy -eq $true) 
{ 
    Start-Sleep -Milliseconds 1000; 
} 
$ie.Document.getElementById("login").value = $username 
$ie.Document.getElementByID("Passwd").value=$password 
$ie.Document.getElementById("cred_sign_in_button").Click();

Currently I have this code which runs in powershell (not sharepoint powershell) it first opens Internet explorer and second enters the login and password.

What I havent been able to do though is to get the code to select the sign in button. Does anyone know what value I should have to get the button to select?

Thanks

It should be this part of the code. $ie.Document.getElementById("cred_sign_in_button").Click();

This is the source code for the sign in button.

      <span id="cred_sign_in_button" tabindex="11" onclick="Post.SubmitCreds();return false;"
            class="button normaltext cred_sign_in_button refresh_domain_state" role="button">Sign in</span>
                    <div id="recover_container" class="subtext smalltext">
          <span>
like image 623
Michael Downey Avatar asked Apr 07 '14 18:04

Michael Downey


1 Answers

To do this you have to download the WASP plugin for PowerShell.

http://wasp.codeplex.com/

After that the following code will do the trick.

$url = "https://example.sharepoint.com/" 
$username="[email protected] " 
$password="Password" 


$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url);


while ($ie.Busy -eq $true) 
{ 
    Start-Sleep -Milliseconds 1000; 
} 
$ie.Document.getElementById("login").value = $username 
$ie.Document.getElementByID("Passwd").value=$password 

Import-Module WASP
$ie = Select-Window IEXPLORE | Set-WindowActive
$ie | Send-Keys "{TAB}"
$ie | Send-Keys "{TAB}"
$ie | Send-Keys "{TAB}"
$ie | Send-Keys "{TAB}"
$ie | Send-Keys "{TAB}"
$ie | Send-Keys "{TAB}"
Start-Sleep -Milliseconds 1000
$ie | Send-Keys "{ENTER}"
like image 56
Michael Downey Avatar answered Oct 04 '22 04:10

Michael Downey