Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AppleScript to automate adding mapped drives to mac via AD
----------------------------------------------------------------------------------------------------
--
-- Drive Mapping Script
-- Original by Ben Toms | MacMule / Modified By: Gilbert Palau
--
----------------------------------------------------------------------------------------------------
-------------------------------
--- User Information Logic
-------------------------------
-- Get the logged in users username
set loggedInUser to do shell script "whoami"
-- Get the Users account UniqueID
set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-"
-- Get the nodeName from the Users account
set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-"
-- Get the Users group membership from AD
set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'"
-- Get the Users AD Home Folder
set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\\\\/\\//g' "
-- set SMBH to do shell script "dscl . read /Users/$USER SMBHome | cut -c 10- | sed 's/\\/\//g'"
-- Checks to see if account is an AD Account, if its not exit
if accountType is less than 1000 then
tell me to quit
end if
------------------------------
--- Drives
------------------------------
--Home Folder -- Maps the drive specified in the profile field for the AD User continue if user has no profile path set
try
mount volume "SMB:" & ADHome
on error
end try
-- Checks ADHome -- contains the correct server then, mounts the shares.
-- Caribbean - on some beach
if ADHome contains "name.of.your.fileserver" then
mount volume "smb://name.of.your.fileserver.fqdn/group"
mount volume "smb://name.of.your.fileserver.fqdn/public"
end if
--- Rinse and repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.