Thursday, July 25, 2019

Work Day PowerShell

$URL = "https://lms.nhcms.net/" #Replace this link with your calendar page (they hardcode your id in the URL)
$Username = "Username" #Replace Username with your LMS Username
$Password = "Password" #Replace Password with your LMS Password

$IE = New-Object -ComObject internetexplorer.application
$IE.visible = $true
$IE.navigate($URL)

While ($IE.Busy -eq $true) {
     Start-Sleep -Seconds 1
} #End while (this is needed to pause internet explorer so it can add the data to the fields.

$IE.document.IHTMLDocument3_getElementByID("UserName").Value = $Username
$IE.Document.IHTMLDocument3_getElementByID("Password").Value = $Password
($IE.Document.IHTMLDocument3_getElementsByTagName("Input") | Where-Object {$_.type -eq "submit" -and $_.value -eq "Login"} | Select-Object -First 1).Click()  #Needed because the LMS does not have ID or Name fields for their buttons


The above script will auto login to a webpage, in this case our LMS system. This uses IE Com object for logging into a website. It only works with IE (no chrome or edge). I use this in a Powershell module called Start-Workday which loads my admin tools I use for the day.

I also created a shortcut for Start-Workday and renamed the script to Work day. This allows me say “Cortana, Start Work day” and Cortana ends up opening IE (LMS site), Edge (Helpdesk ticket system), Outlook, Skype for Business, and Microsoft Teams. There is also an End-Workday module which closes these applications.