Create script for Mapping drive

Nguyen
New Contributor III

Hi All
Could everyone help me to write a script that mapping the windows network share drive. That is when a user is BYOD and just run the script, the script will prompt for authentication and base on the username, the drive will map to correct share folder.
Thanks

6 REPLIES 6

jarednichols
Honored Contributor

Is this the drive defined in their AD object? (SMBHome?)

Nguyen
New Contributor III

Hi Jarednichols

Yes there is and it is smb map share

tkimpton
Valued Contributor II

Would an applescript help?

I use an applescript saved as an application and use mcx to have it as a login item.

It mounts all our standard network shares plus an extra share for our admins, a developer share if the user is a developer.

justinrummel
Contributor III

If this BYOD device is being managed by your JSS, then you should be able to map the drive via MCX or Profile (vs. script).

The issue is to get the SMBHome (or NFSHomeDirectory) path for MCX/Profiles, the machine needs to be bound to your AD environment first. Then it will perform the dscl /Search -read /Users/whoami NFSHomeDirectory command for you. Else this will be a one-off script just for that one person and one machine.

If this is not being managed by your JSS, you are wanting to create the target folder first via mkdir /Volumes/MyShare then use smb_mount command.

- Justin

Andrina
Contributor
Contributor

In fact I've just been working on something very similar... YMMV, but modify as required for your environment - we are using the AD plugin, just don't want to map to the SMB home as it's shared in a non-visible path and gives us a "?" in the dock....

#!/bin/bash

#Mount a users home directory outside of the AD Plugin UNC Path
SMBPATH=`dscl localhost read /Active Directory/DOMAINNAME/All Domains/Users/"$3" SMBHome | awk '{print $2}' | sed -e 's/\\\/smb:///g' | sed 's:\:/:g'`

#Make the users home folder and mount it...
#Get rid of remnants if there was previously an issue...
rmdir /Volumes/foldername
su $3 -c "mkdir /Volumes/foldername; mount -t smbfs -o nodev,nosuid $SMBPATH /Volumes/foldername"

#Place it in the Dock for the user
su $3 -c 'defaults write com.apple.dock persistent-others -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Volumes/foldername</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"'
#restart the Dock to make sure it's there
killall Dock

ArielN
New Contributor

Hi Andrina,
I'm new to scripting, are you still using this script to map users network drives? can you tell me the work flow when the a BYOD or Domain user first login?

Thank You,
Ariel