Script to auto login to office 365 for School District

Home Forums Scripting PowerShell Script to auto login to office 365 for School District

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    jason0923
    Member
    #164616

    The administration wants me to set it up so when a student logs in it logs into office 365 and maps a drive to their one drive for them. Right now they have to open it login SELECT keep me logged in and from there it works. So for example on my PC at some point I had clicked that keep me logged in check box so the script works on mine but on another machine where I have not clicked that box it does not. Below is what I have so far. It works for users who have manually clicked that keep me logged in box but not for new users or those who haven’t. Can anyone tell me whre I’m going wrong?

    #$user = [Environment]::UserName
    $user = “myusername”
    $email = $user + “@emaildomain”
    $sitename = $user + “_email domain”
    $siteurl = “https://oursite-my.sharepoint.com/Personal/$sitename/documents”
    $mapurl = “\[email protected]$sitename/documents”

    # Create the IE com object and logout first
    $ie = new-object -com InternetExplorer.Application
    $ie.visible = $true #Uncomment this for debugging
    $ie.navigate(“http://login.microsoftonline.com/logout.srf”)
    do {sleep 1} until (-not ($ie.Busy))
    $ie.quit()

    $ie = new-object -com InternetExplorer.Application
    $ie.navigate(“https://login.microsoftonline.com/login.srf”)
    $ie.visible = $true #Uncomment this for debugging
    # Wait for the page to finish loading
    do {sleep 1} until (-not ($ie.Busy))
    #while($ie.ReadyState -ne 4) {start-sleep -m 100} # another way to do thisaa
    # We have to click the remember me checkbox before logging in, we also have to have IE be automated for this to work
    try {
    $ie.document.GetElementById(“_link”).click()
    do {sleep 1} until (-not ($ie.Busy))
    } catch {$null}
    try {
    $ie.document.GetElementById(“cred_keep_me_signed_in_checkbox”).click()
    $ie.document.GetElementById(“cred_userid_inputtext”).value = $email
    $ie.document.GetElementById(“cred_sign_in_button”).click()
    #do {sleep 1} until (-not ($ie.Busy))
    } catch {$null}

    sleep -seconds 15 # give plenty of time to redirect
    ie.navigate($siteurl) # open o365 to verify we grab the token
    do {sleep 1} until (-not ($ie.Busy))
    cmd.exe /c ‘c:user dataonedrivemap.cmd’
    sleep -seconds 5 #wait it out for a redirect
    #$ie.quit()[/CODE][CODE]
    #$user = [Environment]::UserName
    $user = “myusername”
    $email = $user + “@emaildomain”
    $sitename = $user + “_email domain”
    $siteurl = “https://oursite-my.sharepoint.com/Personal/$sitename/documents”
    $mapurl = “\[email protected]$sitename/documents”

    # Create the IE com object and logout first
    $ie = new-object -com InternetExplorer.Application
    $ie.visible = $true #Uncomment this for debugging
    $ie.navigate(“http://login.microsoftonline.com/logout.srf”)
    do {sleep 1} until (-not ($ie.Busy))
    $ie.quit()

    $ie = new-object -com InternetExplorer.Application
    $ie.navigate(“https://login.microsoftonline.com/login.srf”)
    $ie.visible = $true #Uncomment this for debugging
    # Wait for the page to finish loading
    do {sleep 1} until (-not ($ie.Busy))
    #while($ie.ReadyState -ne 4) {start-sleep -m 100} # another way to do thisaa
    # We have to click the remember me checkbox before logging in, we also have to have IE be automated for this to work
    try {
    $ie.document.GetElementById(“_link”).click()
    do {sleep 1} until (-not ($ie.Busy))
    } catch {$null}
    try {
    $ie.document.GetElementById(“cred_keep_me_signed_in_checkbox”).click()
    $ie.document.GetElementById(“cred_userid_inputtext”).value = $email
    $ie.document.GetElementById(“cred_sign_in_button”).click()
    #do {sleep 1} until (-not ($ie.Busy))
    } catch {$null}

    sleep -seconds 15 # give plenty of time to redirect
    ie.navigate($siteurl) # open o365 to verify we grab the token
    do {sleep 1} until (-not ($ie.Busy))
    cmd.exe /c ‘c:user dataonedrivemap.cmd’
    sleep -seconds 5 #wait it out for a redirect
    #$ie.quit()[/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.