diff --git a/OneDriveMapper.ps1 b/OneDriveMapper.ps1 index 19b4c8d..5d849ea 100644 --- a/OneDriveMapper.ps1 +++ b/OneDriveMapper.ps1 @@ -1,15 +1,29 @@ -##OneDrive Map to Drive Letter +######## +#OneDriveMapper +# FOR AN UP-TO-DATE VERSION - VISIT: https://gitlab.com/Lieben/OnedriveMapper_V3/blob/master/OneDriveMapper.ps1 +#Copyright: Free to use, please leave this header intact +#Author: Jos Lieben (OGD) +#Company: OGD (http://www.ogd.nl) +#Script help: http://www.lieben.nu, please provide a decrypted Fiddler Trace Log if you're using Native auth and having issues +#Purpose: This script maps Onedrive for Business and/or maps a configurable number of Sharepoint Libraries +#Enterprise users: This script is not recommended for Enterprise use as no dedicated support is available. Check www.lieben.nu for enterprise options. + +#Todo: +#1 remove undesired network locations and do not error out when it already exists and matches the desired location +#2 MFA revamp (done, Native mode only!) +#3 try to use InternetGetCookie function from wininet.dll + param( [Switch]$asTask, [Switch]$fallbackMode, [Switch]$hideConsole ) -$version = "3.19" +$version = "3.21" ####MANDATORY MANUAL CONFIGURATION -$authMethod = "native" #Uses IE automation (old method) when set to ie, uses new native method when set to 'native' -$O365CustomerName = "ogd" #This should be the name of your tenant (example, ogd as in ogd.onmicrosoft.com) +$authMethod = "native" #Uses AzureAD integrated when set to "azure", Uses IE automation (old method) when set to "ie", uses new native method when set to "native" +$O365CustomerName = "ogd" #This should be the name of your tenant (example, ogd as in ogd.onmicrosoft.com) $debugmode = $False #Set to $True for debugging purposes. You'll be able to see the script navigate in Internet Explorer if you're using IE auth mode $userLookupMode = 3 #1 = Active Directory UPN, 2 = Active Directory Email, 3 = Azure AD Joined Windows 10, 4 = query user for his/her login, 5 = lookup by registry key, 6 = display full form (ask for both username and login if no cached versions can be found), 7 = whoami /upn $AzureAADConnectSSO = $False #NOT NEEDED FOR NATIVE AUTH, if set to True, will automatically remove AzureADSSO registry key before mapping, and then readd them after mapping. Otherwise, mapping fails because AzureADSSO creates a non-persistent cookie @@ -52,11 +66,11 @@ $autoMapFavoritesDrive = "S" #Driveletter when using autom $autoMapFavoritesLabel = "Teams" #Label of favorites container, ie; folder name if automapFavoritesMode = "Onedrive", drive label if automapFavoritesMode = "Converged" $autoMapFavoritesDrvLetterList = "DEFGHIJKLMNOPQRSTUVWXYZ" #List of driveletters that shall be used (you can ommit some of yours "reserved" letters) $favoriteSitesDLName = "Gedeelde Documenten" #Normally autodetected, default document library name in Teams/Groups/Sites to map in conjunction with $autoMapFavoriteSites, note the double spaces! Use Shared Documents for english language tenants -$restartExplorer = $False #Leave at False unless you're redirecting folders and they don't get redirected properly +$restartExplorer = $True #You can safely set this to False if you're not redirecting folders $autoResetIE = $False #always clear all Internet Explorer cookies before running (prevents certain occasional issues with IE) $authenticateToProxy = $False #use system proxy settings and authenticate automatically -$libraryName = "Documents" #leave this default, unless you wish to map a non-default onedrive library you've created -$autoKillIE = $True #Kill any running Internet Explorer processes prior to running the script to prevent security errors when mapping +$libraryName = "Documents" #leave this default, unless you wish to map a non-default onedrive library you've created +$autoKillIE = $True #Kill any running Internet Explorer processes prior to running the script to prevent security errors when mapping $abortIfNoAdfs = $False #If set to True, will stop the script if no ADFS server has been detected during login $adfsSmartLink = $Null #If set, the ADFS smartlink will be used to log in to Office 365. For more info, read the FAQ at http://http://www.lieben.nu/liebensraum/onedrivemapper/onedrivemapper-faq/ $displayErrors = $True #show errors to user in visual popups @@ -73,13 +87,12 @@ $urlOpenAfter = "" #This URL will be opened by t $showProgressBar = $True #will show a progress bar to the user $progressBarColor = "#CC99FF" $progressBarText = "OnedriveMapper v$version is connecting your drives..." -$versionCheck = $False #will check if running the latest version, if not, this will be logged to the logfile, no personal data is transmitted. $autoDetectProxy = $False #if set to $False, unchecks the 'Automatically detect proxy settings' setting in IE; this greatly enhanced WebDav performance, set to true to not modify this IE setting (leave as is) $forceUserName = '' #if anything is entered here, userLookupMode is ignored -$forcePassword = '' #if anything is entered here, the user won't be prompted for a password. This function is not recommended, as your password could be stolen from this file -$autoProtectedMode = $True #Automatically temporarily disable IE Protected Mode if it is enabled. ProtectedMode has to be disabled for the script to function +$forcePassword = '' #if anything is entered here, the user won't be prompted for a password. This function is not recommended, as your password could be stolen from this file +$autoProtectedMode = $True #Automatically temporarily disable IE Protected Mode if it is enabled. ProtectedMode has to be disabled for the script to function $addShellLink = $False #Adds a link to Onedrive to the Shell under Favorites (Windows 7, 8 / 2008R2 and 2012R2 only) If you use a remote path, google EnableShellShortcutIconRemotePath -$logfile = ($env:APPDATA + "\OneDriveMapper_$version.log") #Logfile to log to +$logfile = ($env:APPDATA + "\OneDriveMapper_$version.log") #Logfile to log to $pwdCache = ($env:APPDATA + "\OneDriveMapper.tmp") #file to store encrypted password into, change to $Null to disable $loginCache = ($env:APPDATA + "\OneDriveMapper.tmp2") #file to store encrypted login into, change to $Null to disable $allowFallbackMode = $True #if set to True, and the selected authentication method fails, onedrivemapper will try again using the other authentication method @@ -97,13 +110,13 @@ if($showConsoleOutput -eq $False){ }catch{$Null} } -######## +######## #Required resources and some customizations you'll probably not use -######## +######## $arguments = "& '" + $myinvocation.mycommand.definition + "'" -$mapresult = $False +$mapresult = $False -$protectedModeValues = @{} +$protectedModeValues = @{} $privateSuffix = "-my" $script:errorsForUser = "" $userLoginRegistryKey = "HKCU:\System\CurrentControlSet\Control\CustomUID" @@ -120,17 +133,11 @@ if($adfsSmartLink){ $o365loginURL = "https://login.microsoftonline.com/login.srf?msafed=0" } -$O365CustomerName = $O365CustomerName.ToLower() +$O365CustomerName = $O365CustomerName.ToLower() #for people that don't RTFM, fix wrongly entered customer names: $O365CustomerName = $O365CustomerName -Replace ".onmicrosoft.com","" -$forceUserName = $forceUserName.ToLower() -$finalURLs = @() -$finalURLs += "https://portal.office.com" -$finalURLs += "https://outlook.office365.com" -$finalURLs += "https://outlook.office.com" -$finalURLs += "https://$($O365CustomerName)-my.sharepoint.com" -$finalURLs += "https://$($O365CustomerName).sharepoint.com" -$finalURLs += "https://www.office.com" +$forceUserName = $forceUserName.ToLower() +$finalURLs = @("https://portal.office.com","https://outlook.office365.com","https://outlook.office.com","https://$($O365CustomerName)-my.sharepoint.com","https://$($O365CustomerName).sharepoint.com","https://www.office.com") function log{ param ( @@ -185,7 +192,7 @@ function ResetLog{ #Already a backup file, delete it Remove-Item ($logfile + ".old") -Force -Confirm:$False } - #Now lets rename + #Now lets rename Rename-Item -path $logfile -NewName ($logfile + ".old") -Force -Confirm:$False #Start a new log log -text "******** Log file reset after reaching maximum size ********`n" @@ -198,13 +205,13 @@ function ResetLog{ $scriptPath = $MyInvocation.MyCommand.Definition ResetLog -log -text "-----$(Get-Date) OneDriveMapper v$version - $($env:USERNAME) on $($env:COMPUTERNAME) starting-----" +log -text "-----$(Get-Date) OneDriveMapper v$version - $($env:USERNAME) on $($env:COMPUTERNAME) starting-----" ###THIS ONLY HAS TO BE CONFIGURED IF YOU WANT TO MAP USER SECURITY GROUPS TO SHAREPOINT SITES if($desiredMappings.mapOnlyForSpecificGroup | Where-Object{$_.Length -gt 0}){ try{ $groups = ([ADSISEARCHER]"(member:1.2.840.113556.1.4.1941:=$(([ADSISEARCHER]"samaccountname=$($env:USERNAME)").FindOne().Properties.distinguishedname))").FindAll().Properties.distinguishedname -replace '^CN=([^,]+).+$','$1' - log -text "cached user group membership because you have configured mappings where the mapOnlyForSpecificGroup option was configured" + log -text "cached user group membership because you have configured mappings where the mapOnlyForSpecificGroup option was configured" }catch{ log -text "failed to cache user group membership, ignoring these mappings because of: $($Error[0])" -fout $desiredMappings = $desiredMappings | Where-Object{$_.mapOnlyForSpecificGroup.Length -eq 0} @@ -296,7 +303,7 @@ function Add-NetworkLocation $Shortcut.TargetPath = $networkLocationTarget if([System.IO.File]::Exists($iconPath)){ $Shortcut.IconLocation = "$($iconPath), 0" - } + } $Shortcut.Description = "Created $(Get-Date -Format s) by $($MyInvocation.MyCommand)." $Shortcut.Save() } @@ -309,28 +316,6 @@ function Add-NetworkLocation } } -function handleSpoReAuth{ - Param( - $res - ) - try{ - if((returnEnclosedFormValue -res $res -searchString "