Created
April 7, 2016 19:58
-
-
Save BeanBagKing/fec7cb7a77e6b1f9c965694172b99160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This was, ideally, a way to map SharePoint drives as network drives in Windows. I don't believe I ever got it working, but maybe | |
# it will come in handy for someone. | |
# http://community.office365.com/en-us/f/173/t/286802.aspx | |
# Reference the above for "steps" | |
# Adds sharepoint.com to the list of trusted sites | |
# AKA Step 1 | |
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\sharepoint.com\georgiahighlands2-my" –Force | |
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\sharepoint.com\georgiahighlands2-my" -Name https -PropertyType DWord -Value 00000002 –Force | |
# Username and password, stored as variables for logging them in. | |
$user = Read-Host 'What is your username?' | |
$pass = Read-Host 'What is your password?' -AsSecureString | |
$emaildomain = "highlands.edu" | |
$emailusername = $user + "@" + $emaildomain | |
$urlsite = 'https://georgiahighlands2-my.sharepoint.com/personal/' | |
$urldomain = "_highlands_edu" | |
$urlFile = $urlsite + $user + $urldomain + "/Documents" | |
$mapsite = '\\georgiahighlands2-my.sharepoint.com@SSL\DavWWWRoot\personal\' # This could be encoded from the above but perhaps another revision | |
#$mapPath = $mapsite + $user + $urldomain + "\Documents" | |
$mapPath = "https://georgiahighlands2-my.sharepoint.com/personal/" + $user + "_highlands_edu/Documents" | |
# Logs the user out of an active sessions | |
$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() | |
# Logs the user in | |
# AKA step 2 | |
$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 this | |
# 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 = $emailusername | |
$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.document.GetElementById("passwordInput").value = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)) | |
$ie.document.GetElementById("submitButton").click() | |
sleep -seconds 5 # give plenty of time to redirect | |
$ie.navigate($urlFile) # open o365 to verify we grab the token | |
do {sleep 1} until (-not ($ie.Busy)) | |
sleep -seconds 5 #wait it out for a redirect | |
#$ie.quit() | |
# Step 5-7, mount the drive! | |
net use O: $mapPath /persistent:yes /User:$emailusername $pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment