OneDriveMapper automatically map your OneDrive for Business upon login

This script maps your Onedrive / Sharepoint / Teams document libraries to driveletters (or shortcuts). It can be used in any environment (VDI, RemoteApp, w10 etc).

 
 
 
 
 
4.6 Star
(112)
65,067 times
Add to favorites
Office 365
2/3/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Mapped Drive space isn't accurate, Prompts, Sharepoint.
    2 Posts | Last post May 10, 2016
    • Hi, 
      I've had some success using this tool, but have a few questions that I hope you can assist.  
      
      my environment - Win7, ADFS, onedrive, O365, Sharepoint
      
      1. Once the drive is mapped it's not showing the space accurately, it's mirroring the space details of the C:\ Drive.  Anyway to match the 1TB or whatever the user has? 
      
      2. I feel like I am getting one too many prompts.  For example, I am prompted One time from the custom form for a username(O365 UPN doesn't match computer login) then a second custom form for pwd.  While this is happening I also get a security prompt from IE asking for the same details.  Is this for the same thing?  Can one do the job of the other?  
      
      3. The sharepoint documents mapping.  My library has a space in the name, what should my syntax look like?  
      Here's my entry. 
      
      $showConsoleOutput     = $True                     #Set this to $False to hide console output
      $showElevatedConsole   = $True
      $sharepointMappings    = @()
      $sharepointMappings    += "https://ogd.sharepoint.com/site1/documentsLibrary,ExampleLabel,Y:"
      $sharepointMappings    += "https://bw.sharepoint.com/brytest/Shared Documents,brylabel,U:"
       
      
      
      
    • 1: this is by design by Microsoft for webdav drives
      2: that IE prompt is probably ADFS, the script only supports SSO OR Forms-based authentication modes in ADFS, the IE popup can't easily be accessed via script. 
      3: either Shared%20%20Documents or Shared%20Documents should work
  • OneDrive for Business Only?
    2 Posts | Last post May 10, 2016
    • Awesome work, thanks! Do you know if this will work for non-Business OneDrive, like through an outlook.com address?
      
      Josh
    • I'm afraid not
  • Default page in O365
    2 Posts | Last post May 04, 2016
    • Hi,
      
      When I run the script everything work well for a user but it's not working for others. I found a way to fix the problem but I would like to have a solution that does not require user interaction.
      
      When I run the script and the user default login page in Office 365 is OneDrive everything work fine. The users have the default login page with link to all the applications (Word, Excel, etc.) and the script dont seem's able to redirect to OneDrive from here.
      
      The default login page is https://www.office.com/1?auth=2&home=1&from=PortalLanding&client-request-id=f966e422-58be-47ab-bf6c-d5d0b4ba5784
      
      The working login page (oneDrive) is https://csduroy-my.sharepoint.com/personal/user_name_csduroy_qc_ca/_layouts/15/onedrive.aspx
      
      I dont want to change the login page (as the users can choose any apps from there and download Office) but I would love this script to work.
      
      Any tips?
      
    • ah, sure, that's easy to fix, I haven't seen that domain being used as a start page before, just add this line at line 153 of the script:
      
      $finalURLs += "https://www.office.com"
      
      Enjoy ;)
  • Error while mapping One Drive to a network drive
    6 Posts | Last post April 28, 2016
    • Hi
      
          I am using the script to map my One Drive for Business on my desktop. The scripts ends without error. But the drives are not mapped. I had look into the log file and it shows this. Please let me know how to solve it
      
      lookupUPNbySAM is set to True -> Using UPNlookup by SAMAccountName feature
      Script elevation level: Administrator
      Possible critical error: Microsoft Office installation not detected, script may fail
      NOTICE: HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Security HKLM only not found in registry, your zone configuration could be set on both levels
      Possible critical error: onevmw.sharepoint.com not found in IE Trusted Sites on user or machine level, the script will likely fail
      Possible critical error: onevmw-my.sharepoint.com not found in IE Trusted Sites on user or machine level, the script will likely fail
      WARNING: WebDav File Locking support is enabled, this could cause files to become locked in your OneDrive
      Adding to mapping list: X: (\\onevmw-my.sharepoint.com@SSL\DavWWWRoot\personal\)
      X: is not yet mapped
      Base URL: https://onevmw-my.sharepoint.com 
      
      autoKillIE enabled, stopping IE processes
      Stopped process with handle 17716
      Stopped process with handle 2016
      autoProtectedMode is set to True, disabling ProtectedMode temporarily
      Zone 0 was set to 3, setting it to 3
      Zone 1 was set to 3, setting it to 3
      Zone 2 was set to 3, setting it to 3
      Zone 3 was set to 3, setting it to 3
      Zone 4 was set to 3, setting it to 3
      current URL: https://login.microsoftonline.com/
      Detected running explorer process
      Login attempt at Office 365 signin page
      Found sign in elements type 2 on Office 365 login page, proceeding
      attempting to trigger a redirect to ADFS
      login detected, login function succeeded, final url: https://portal.office.com/Home
      Failed to get the username from the URL for 30 seconds, aborting
      autoProtectedMode is set to True, reverting to old settings
    • You can find my reply at my blog, as you asked there as well (thanks!) :)
      
      I've also uploaded a slightly modified v2.28 which logs more info when it can't find the username.
    • I have tried using v2.29 and still the sam error. Attaching the error log below
      -----04/28/2016 12:31:33 OneDriveMapper V2.29 - graja on 1CLOUD-120 Session log-----
      lookupUPNbySAM is set to True -> Using UPNlookup by SAMAccountName feature
      Script elevation level: Administrator
      Possible critical error: Microsoft Office installation not detected, script may fail
      NOTICE: HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Security HKLM only not found in registry, your zone configuration could be set on both levels
      NOTICE: onevmw-my.sharepoint.com found in IE Trusted Sites on user level
      Possible critical error: onevmw.sharepoint.com not found in IE Trusted Sites on user or machine level, the script will likely fail
      WARNING: WebDav File Locking support is enabled, this could cause files to become locked in your OneDrive
      Adding to mapping list: X: (\\onevmw-my.sharepoint.com@SSL\DavWWWRoot\personal\)
      X: is not yet mapped
      Base URL: https://onevmw-my.sharepoint.com 
      autoKillIE enabled, stopping IE processes
      Stopped process with handle 8196
      Stopped process with handle 10700
      autoProtectedMode is set to True, disabling ProtectedMode temporarily
      Zone 0 was set to 3, setting it to 3
      Zone 1 was set to 3, setting it to 3
      Zone 2 was set to 3, setting it to 3
      Zone 3 was set to 3, setting it to 3
      Zone 4 was set to 3, setting it to 3
      current URL: https://login.microsoftonline.com/
      Detected running explorer process
      Login attempt at Office 365 signin page
      Found sign in elements type 1 on Office 365 login page, proceeding
      Found sign in elements type 2 on Office 365 login page, proceeding
      Found sign in elements type 3 on Office 365 login page, proceeding
      attempting to trigger a redirect to ADFS using method 1
      login detected, login function succeeded, final url: https://portal.office.com/Home
      Attempting to retrieve the username by browsing to https://onevmw-my.sharepoint.com...
      Failed to get the username from the URL for 30 seconds while at https://onevmw-my.share
    • the final part of the log is important, I can't help you if you only post a part of it.
    • Please find the last part of the log
      
      Failed to get the username from the URL for 30 seconds while at https://onevmw-my.sharepoint.com/_layouts/15/start.aspx#/SitePages/Home.aspx, aborting
      autoProtectedMode is set to True, reverting to old settings
      Setting zone 0 back to 3
      Setting zone 1 back to 3
      Setting zone 2 back to 3
      Setting zone 3 back to 3
      Setting zone 4 back to 3
      OnedriveMapper has finished running
    • looks like you're redirected to a custom page, instead of the normal Onedrive page. Browsing to https://tenant-my.sharepoint.com usually redirects to Onedrive for Business for that user. 
      
      I'm afraid the script can't be built to handle unexpected situations like that unless I have access to such environments. You can email me at josliebennu (put the right characters between sl and nn) if you want to hire me to customize it for your specific implementation.
  • Unexpected URL
    7 Posts | Last post April 27, 2016
    • I'm getting the following error, but I can 100% confirm I don't have a password issue. Any thoughts? Thanks!!!
      
      We attempted to login without using ADFS, but did not end up at the expected location. Detected url: https://account.activedirectory.windowsazure.com/passwordreset/register.aspx?sspr=1&sspr=1&brandcontextid=O365, expected URL: https://sagu-my.sharepoint.com
    • Looks like you enabled self service password reset for this user but did not register for it yet at the specified url.
    • Perfect, thank you! One more: I have had a couple folks time out the first time when it's looking up the username. I just run it again, and it's fine; but was wondering if I could change that wait time here:
      if($dontMapO4B -eq $False){
          while($url.IndexOf("/personal/") -eq -1){
              Sleep -s 3
              $timeSpent++
              $ie.navigate($baseURL)
              do {sleep -m 100} until (-not ($ie.Busy))  
              do {sleep -m 100} until ($ie.ReadyState -eq 4 -or $ie.ReadyState -eq 0)  
              $url = $ie.LocationURL
              if($timeSpent -gt 10){
                  ac $logfile "Failed to get the username from the URL for 30 seconds while at $url, aborting" 
                  $errorsForUser += "Mapping cannot continue because we cannot detect your username`n"
                  abort_OM 
              }
          }
    • certainly, you could increase the number 10 to, for example, 20, then it would wait for 60 seconds. If this is happening because your users had never accessed onedrive before, I recommend you use O365Migrator to preprovision their Onedrive storage.
    • Awesome; thanks so much!
    • I actually had one more strange thing pop-up. When it lists the size of the drive, it simply copies what is available in C, instead of an accurate limit. Anyway to bypass this? I want to copy a large chunk of data, but can't because windows thinks I don't have enough space.
      
      Thanks again!
    • Hi James, 
      
      i'm afraid that that is a bug or 'feature' in the WebDav client, it's been that way since it exists and I don't know of a workaround.
  • Unexpected URL
    1 Posts | Last post April 26, 2016
    • I'm getting the following error, but I can 100% confirm I don't have a password issue. Any thoughts? Thanks!!!
      
      We attempted to login without using ADFS, but did not end up at the expected location. Detected url: https://account.activedirectory.windowsazure.com/passwordreset/register.aspx?sspr=1&sspr=1&brandcontextid=O365, expected URL: https://sagu-my.sharepoint.com
  • V 2.28 -> error message
    3 Posts | Last post April 07, 2016
    • Hi Jos,
      
      I use the script for mapping a SharePoint library as a drive in a RDS environment.
      The mapping as such is working fine, but the users get the following error-message:
      
      The object invoked has disconnected from its clients. (Exception from HRESULT:
      0x80010108 (RPC_E_DISCONNECTED))
      At C:\xxx\xxx\xxxx\OneDriveMapper_xxx.ps1:344 char:11
      +       if ($ShellWindows.Item($i).FullName -like "*iexplore.exe")
      +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : OperationStopped: (:) [], COMException
          + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
      
      
      The onedrivemapper.log looks perfectly fine.
      I am using the script you provided 2 days ago.
      
      Do you have an idea how to get rid of this message?
      
      Benni
    • Because of the diversity in implementations out there, the script has two methods to remove the used Internet Explorer objects for login+mapping. You can safely ignore this error. If you don't want the user to see it, I recommend running the script in hidden mode (instructions on my blog).
      
      Alternatively you could nest the second part in a try/catch loop and hide the error that way.
    • Thanks for the feedback.
      ... running smoothly in the background now ...
      
      
  • V2.28 not working
    7 Posts | Last post April 04, 2016
    • Hi all,
      
      I am successfully running version 2.21 of this great script.
      But when I want to upgrade it to 2.28 (or 2.27), I always run into errors.
      See the contents of the logfile:
      
      -----04/04/2016 10:00:02 OneDriveMapper V2.28 - <username> on <servername> Session log-----
      lookupUPNbySAM is set to True -> Using UPNlookup by SAMAccountName feature
      
      Script elevation level: Administrator
      NOTICE: HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Security HKLM only not found in registry, your zone configuration could be set on both levels
      NOTICE: XYZ-my.sharepoint.com found in IE Trusted Sites on user level
      NOTICE: XYZ.sharepoint.com found in IE Trusted Sites on machine level
      Adding to mapping list: Q: (\\XYZ-my.sharepoint.com@SSL\DavWWWRoot\personal\)
      Adding to mapping list: Q: (\\XYZ.sharepoint.com@SSL\sites\AAAAA\BBBB\)
      Q: is not yet mapped
      Q: is not yet mapped
      Base URL: https://XYZ-my.sharepoint.com 
      
      WARNING: no instances of Internet Explorer running yet, at least one should be running
      autoProtectedMode is set to True, disabling ProtectedMode temporarily
      Zone 0 was set to 3, setting it to 3
      Zone 1 was set to 3, setting it to 3
      Zone 2 was set to 3, setting it to 3
      Zone 3 was set to 3, setting it to 3
      Zone 4 was set to 3, setting it to 3
      current URL: https://login.microsoftonline.com/
      Detected running explorer process
      Login attempt at Office 365 signin page
      Found sign in elements type 2 on Office 365 login page, proceeding
      attempting to trigger a redirect to ADFS
      login detected, login function succeeded, final url: https://XYZ-my.sharepoint.com/_layouts/15/me.aspx
      Failed to get the username from the URL for 30 seconds, aborting
      
      
      Do you have an idea?
      
      Benni
      
      
    • You're just mapping Onedrive? Then leave line 80/81 of the script to it's default, that is meant to map a sharepoint library but you're setting it to your onedrive URL (or so it seems).
    • Hi Jos,
      
      just checked the script. It looks like the following:
      
      Line 78 $sharepointMappings = @()
      Line 79 $sharepointMappings += "https://XYZ.sharepoint.com/sites/AAAAA/BBBB/,BBBB,Q:"
      Line 80 #for each sharepoint site you wish to map 3 comma seperated values are required, the 'clean' url to the library, the desired drive label, and the driveletter
      Line 81 #if you wish to add more, copy the example as you see above, if you don't wish to map any sharepoint sites, simply remove the line or clear everything between the quo....
      
      The lines you mentioned are only comments. I assume you mixed it up.
      Do you mean the lines 78 and 79 instead?
      
      Line 78 is on default and Line 79 has been adapted?
      
      Should it look like that?
      
      $sharepointMappings += "https://XYZ.sharepoint.com/site1/documentsLibrary,testLabel,Y:"
      
      Benni
      
      
    • Hi Jos,
      
      I just realized the I did not answer your question. :(
      No, I don't map one-drive, I am mapping a SharePoint library.
      
      Benni
    • Ah yes, 79, true.
      
      If you're not mapping O4B, you should set $dontMapO4B to $False.
      Now you're basically telling the script to map O4B to Q: and then map a Sharepoint Library to Q: as well.
      
      Secondly, I see you've customized your implementation, the user does not end up at his O4B after logging in but at me.aspx. I've adjusted the script to not fail when this is the case, you'll have to redownload v2.28.
    • Thanks Jos.
      I am going to test and come back.
    • Hi Jos,
      
      I confirm that it is working fine now.
      Many thanks for your quick support.
      
      In addition many thanks keeping this script up-to-date and helping 
      us to fix our issues.
      
      Benni
  • Won't add drive after prompt for password
    6 Posts | Last post April 02, 2016
    • Hello,
      
      I think I managed to 'connect' to my O4B (purchased O365 through godaddy which), but the drive won't show in explorer. I think it's because i'm missing some final steps regarding my PC-settings. 
      
      This is what the log says in the end:
      
      lookupUPNbySAM is set to False -> Using Joris@*********.nl from the currently logged in username + *********.nl
      Script elevation level: Administrator
      NOTICE: HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Security HKLM only not found in registry, your zone configuration could be set on both levels
      Possible critical error: netorgft1165353.onmicrosoft.com.sharepoint.com not found in IE Trusted Sites on user or machine level, the script will likely fail
      Possible critical error: netorgft1165353.onmicrosoft.com-my.sharepoint.com not found in IE Trusted Sites on user or machine level, the script will likely fail
      WARNING: HKLM:\Software\Policies\Microsoft\Internet Explorer\Main\DisableFirstRunCustomize not found in registry, if script hangs this may be due to the First Run popup in IE
      Possible error: HKLM:\Software\Policies\Microsoft\Internet Explorer\Main\DisableFirstRunCustomize not set
      Adding to mapping list: X: (\\netorgft1165353.onmicrosoft.com-my.sharepoint.com@SSL\DavWWWRoot\personal\)
      X: is not yet mapped
      
      I checked the trusted websites, this is ok. 
      The register keys are indeed missing, could this be the problem? How do I add these?
      
      Kind regards,
      
      Joris
    • I'd recommend following the installation instructions on my blog. You'll also have to set the $forceUserName variable I think, as it seems you're running it on a non-domain machine.
      
      And $O365CustomerName should be set to the TENANT name, not to the whole domain name (so no onmicrosoft.com)
      
      blog: http://www.liebensraum.nl
      
    • Hi Jos,
      
      Thanks for the quick reply. I Adjusted the settings and came a bit further.
      
      
      Login attempt at Office 365 signin page
      Found sign in elements type 2 on Office 365 login page, proceeding
      attempting to trigger a redirect to ADFS
      Login splitter detected, your account is both known as a personal and business account, selecting business account..
      waited for more than 10 to get redirected to ADFS, checking if we were properly redirected or attempting normal signin
      asking user for password
      Failed to find the correct controls at https://sso.godaddy.com/?domain=********.nl&realm=pass&app=o365&username=********&wa=wsignin1.0&wtrealm=urn%3afederation%3aMicrosoftOnline&wctx=estsredirect%3d2%26estsrequest%3drQIIAbPSySgpKSi20tcvyC8qSczRy81MLsovzk8ryc_LycxL1UvOz9XLL0rPTAGxioS4BJ4dLK5ZK7rBd0PL8pRwm6CqVYzKhI3Qv8DI-IKR8RaToH9RumdKeLFbakpqUWJJZn7eIybe0OLUIv-8nMqQ_OzUvEnMfDn56Zl58cVFafFpOfnlQAGgCQWJySXxJZnJ2aklu5hVUszNE83NzFN0LS1STHRNTMxNdC3Skox0zYxMU1MtU1OMjS2NL7AI_GBhPMDJCAA1%26LoginOptions%3d1&popupui=&LoginOptions=1 to log in by script, check your browser and proxy settings or check for an update of this script
      autoProtectedMode is set to True, reverting to old settings
      
      I think it's because login.microsoftonline.com redirects me to godaddy login site. 
      On the godaddy site the script doesn't recognize the controls. 
      
      Any clue.
      
      
    • Any clue is welcome I meant to say ofcourse.. :-)
      
      Thanks in advance.
      
      Joris
    • Okay, I managed to fix it. Think what solved is was:
      
      $urlOpenAfter       = "https://portal.office.com/Home/"
      $debugmode          = $True
      
      By putting debug mode on "True" I was able to manually bypass the "Godaddy" login screen. I Hope this helps for others who might experience comparable issues.
      
      Furthermore, I have two questions:
      - The script added two shares, instead of one. How do I remove one from the explorer?
      - Is it possible to set a password/pin for the share for each time I boot my PC?
      
      Kind regards,
      
      Joris
    • hmmm, I didn't know godaddy did a redirect / SSO on their own, you'd have to figure out the ID's of the form elements they use so you don't have to manually get around it.
      
      Two shares: you probably configured a sharepoint mapping, it would otherwise never map two drives.
      
      Password/pin: not without third party software
  • Issue on Server 2012 R2
    3 Posts | Last post April 01, 2016
    • Hi there Jos, 
      
      First of all, thanks for creating such a useful script. Personally I will be using this to create a persistent mapped drive on a single server. This mapped drive will allow our MFD scanner to scan documents into SharePoint Online directly :)
      
      I am having the following problem when I run the script:
      
      Error message displayed on screen:
      Cannot find an overload for "getElementById" and the argument count: "1".
      At C:\Users\administrator\Downloads\OneDriveMapper_v2.22.ps1:347 char:8
      +     if($ie.document.GetElementById("_link").tagName -ne $Null){
      +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodException
          + FullyQualifiedErrorId : MethodCountCouldNotFindBest
      
      Last lines of log file (note, we are not using ADFS):
      Detected running explorer process
      Login attempt at Office 365 signin page
      attempting to trigger a redirect to ADFS
      Failed to find the correct controls at https://login.microsoftonline.com/login.srf?wa=wsignin1%2E0&rpsnv=4&ct=1449571833&rver=6%2E1%2E6206%2E0&wp=MBI&wreply=https%3A%2F%2Fhealthenterpriseeastcouk%2Esharepoint%2Ecom%2F%5Fforms%2Fdefault%2Easpx%3Fapr%3D1&lc=1033&id=500046&guests=1 to log in by script, check your browser and proxy settings or check for an update of this script
      autoProtectedMode is set to True, reverting to old settings
      Setting zone 1 back to 3
      
      
      The server is hosted in Azure and IE is configured to auto detect LAN settings. Any ideas what might be causing this?
      
      Thanks,
      
      David
    • Hi David,
      
      nice idea :) You could also use a mail-enabled document library in Sharepoint to do that, and have it mail it there.
      
      As for the error, I'd need the full log I'm afraid....
      
      If you don't want to post it here you can email it to josliebennu where the at is between sl and the dot is between nn
    • Hello David and Jos,
      
      Did you both manage to solve the issue regarding "finding the correct controls"?
      I think I'm currently experiencing the same issue.
      
      Thanks,
      
      Joris
      
151 - 160 of 191 Items