Link to home
Start Free TrialLog in
Avatar of John Davies
John DaviesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Script to Map Sharepoint Drive

I want to write a batch file that I can distribute to users that will map their sharepoint secure folder, have the UNC that will prompt them for logon name and password for sharepoint when run and when the cookie times out and the connection drops they can simply click the batch file and remap

net use i: /delete
net use i: "\\XXX.sharepoint.com@SSL/DavWWWRoot/sites/Commercial/Team Secure/" USER:email address * /PERSISTENT:YES

No domain, sharepoint online
* dont want to store password, want to prompt


Any help appreciated

John
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
Flag of United States of America image

I believe this should do as expected.  Not sure as it's been ages since I mapped a sharepoint server, but I believe you need to change all of your /s to \s

REM Script: MapSharepoint.cmd
@(
	setlocal enabledelayedexpansion
	echo off
	SET "_SharepointPath=\\XXX.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure" /Persistent:NO
	SET "_Email="
	SET "_PW="
	SET "_eLvl=0"
)

CALL :Main

(
	ENDLOCAL
	EXIT /B %_eLvl%
)

:Main
	SETLOCAL
	ECHO. Mapping Folder "%_SharepointPath%"
	ECHO. 
	
	SET /P "_Email=Please Enter your email address to authenticate with: "
	IF NOT DEFINED _Email (
		ECHO. Aborting!  No Email Provided!
		SET "_eLvl=1"
		GOTO :EOF
	)
	
	SET /P "_PW=Please Enter your Password: "
	IF NOT DEFINED _PW (
		ECHO. Aborting!  No Password Provided!
		SET "_eLvl=2"
		GOTO :EOF
	)
	
	NET USE I: /D /Y >NUL
	NET USE I: /D /Y >NUL
	NET USE >NUL
	(
		NET USE I: "%_SharepointPath%" USER:%_Email% %_PW%
	) || (
		ECHO. Drive Mapping Failed!
		SET "_eLvl=3"
	)
	(
		ENDLOCAL
		SET "_PW="
		SET "_eLvl=%_eLvl%"
	)
GOTO :EOF

Open in new window

Avatar of John Davies

ASKER

Have tried it and didn't see the mapping appear (changed the drive mapping to suit), Have copied the link and can see the shared folder. no mapping :-)

ERROR The logon and password were tests

Please Enter your email address to authenticate with: lkij
Please Enter your Password: jhjhjh
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The syntax of this command is:

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]

 Drive Mapping Failed
@John Davies.

 The reason it didn't map correctly was most likely due to my minor syntax issue here I left the "/" off "/User:" (Oops!)

  Also, I thought I posted the amended version of this code that had "/Persistent:NO"** on the command but I put it on the variable for the sharepoint path, which should have been ignored but could have caused an issue.

I have fixed both below.


(**BTW: You don't want these to be persistent, you want to re-map them each time the user logs on, otherwise they will be issues.  If you do want the path to be mapped once and stick around, you might want to use a Symbolic link instead, so the remote SharePoint is mounted as a folder on the operating system instead of a drive.)



REM Script: MapSharepoint.cmd
@(
	setlocal enabledelayedexpansion
	echo off
	SET "_SharepointPath=\\XXX.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure"
	SET "_Email="
	SET "_PW="
	SET "_eLvl=0"
)

CALL :Main

(
	ENDLOCAL
	EXIT /B %_eLvl%
)

:Main
	SETLOCAL
	ECHO. Mapping Folder "%_SharepointPath%"
	ECHO. 
	
	SET /P "_Email=Please Enter your email address to authenticate with: "
	IF NOT DEFINED _Email (
		ECHO. Aborting!  No Email Provided!
		SET "_eLvl=1"
		GOTO :EOF
	)
	
	SET /P "_PW=Please Enter your Password: "
	IF NOT DEFINED _PW (
		ECHO. Aborting!  No Password Provided!
		SET "_eLvl=2"
		GOTO :EOF
	)
	
	NET USE I: /D /Y >NUL
	NET USE I: /D /Y >NUL
	NET USE >NUL
	(
		NET USE I: "%_SharepointPath%" /USER:%_Email% %_PW% /Persistent:NO
	) || (
		ECHO. Drive Mapping Failed!
		SET "_eLvl=3"
	)
	(
		ENDLOCAL
		SET "_PW="
		SET "_eLvl=%_eLvl%"
	)
GOTO :EOF

Open in new window

Hi Ben,

Really appreciate your help here, so close but still getting the error.

Made a change to the domain in the sharepoint link and didnt change anything else.

Pasting into browser - \\xxx.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure - worked
Pasting into cmd - net use i: \\xxx.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure - didnt work, handle the space in script

Run whole script

C:\Users\LAPTOP\Desktop\Bat Files>REM Script: MapSharepoint.cmd
 Mapping Folder "\\xxx.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\"

Please Enter your email address to authenticate with: ddsbvdfgvdf@test.com
Please Enter your Password: vfadvdfb
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

System error 53 has occurred.

The network path was not found.

 Drive Mapping Failed
Press any key to continue . . .

So it looks like the handling of the space may is causing the issue Ben, have tried the quotes :-(

Thanks Again

John
ASKER CERTIFIED SOLUTION
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, team secure is a valid document library. I have permissions in it, can map through browser to it via

\\xxx.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure\

Can map a drive via

https://xxx.sharepoint.com/sites/Commercial/Team Secure/

But need to script it

Not changed any of the script other than the Sharepoint Doc Library location

REM Script: MapSharepoint.cmd
@(
      setlocal enabledelayedexpansion
      echo off
      SET "_SharepointPath=\\xxx.sharepoint.com@SSL\DavWWWRoot\sites\Commercial\Team Secure\"
      SET "_Email="
      SET "_PW="
      SET "_eLvl=0"
)

CALL :Main

(
      ENDLOCAL
      EXIT /B %_eLvl%
)

:Main
      SETLOCAL
      ECHO. Mapping Folder "%_SharepointPath%"
      ECHO.
      
      SET /P "_Email=Please Enter your email address to authenticate with: "
      IF NOT DEFINED _Email (
            ECHO. Aborting!  No Email Provided!
            SET "_eLvl=1"
            GOTO :EOF
      )
      
      SET /P "_PW=Please Enter your Password: "
      IF NOT DEFINED _PW (
            ECHO. Aborting!  No Password Provided!
            SET "_eLvl=2"
            GOTO :EOF
      )
      
      NET USE I: /D /Y >NUL
      NET USE I: /D /Y >NUL
      NET USE >NUL
      (
            NET USE I: "%_SharepointPath%" /USER:%_Email% %_PW% /Persistent:NO
      ) || (
            ECHO. Drive Mapping Failed!
            SET "_eLvl=3"
      )
      (
            ENDLOCAL
            SET "_PW="
            SET "_eLvl=%_eLvl%"
      )
Pause
GOTO :EOF

Trying this on my machine, signing out, removing shares, reboots etc.

Thanks

John
No Joy Ben :-( still not mapping...
Didnt quite work but happy with the effort put in. Thanks
Avatar of Tracy Welsh
Tracy Welsh

Not sure if you ever got this working.  I work for the developer of a commercial client application that will do this.  The drive can remain persistent and WebDAV file locking is supported.  There's a 10 day free trial if you want to try it out.  www.webdrive.com