Convert Local Account’s Home to AD account with Local Home

Here is a script that I use to convert a local home folder to be used by an Active Directory account. This script will rename the home folder first, then delete the local user account from NetInfo and rename the home folder back and change the permissions so the AD account can use the home folder. This script is Tiger only.

Please read the script before using so you understand how it works. It’s not terribly complicated.

Use at your own risk!

Download here

(*
 
Convert User to Domain account
Does not require modification for your enviornment. Can be run as is. 
 
TIGER ONLY. 
Leopard does not hve NI* utilities.
 
Copyright 2007 Patrick Gallagher
http://blog.macadmincorner.com
 
USE AT YOUR OWN RISK
NO WARRANTY EXPRESSED OR IMPLIED
*)
 
--Pick a local user from list of home folders that are present in /Users
--You can add a "| grep -v yourlocaladminaccount" after "Shared" if you wish to exclude that from the list
set userList to paragraphs of (do shell script "ls -1d /Users/* | cut -d/ -f3 | grep -v Shared")
set localName to choose from list userList
if localName is not equal to false then
 
	--Backup users home folder
	do shell script "mv /Users/" & localName & " /Users/" & localName & ".backup" with administrator privileges
else if localName is equal to false then
	display dialog "Operation cancelled"
end if
 
--Nuke the local account
do shell script "niutil -destroyval / /groups/staff users " & localName with administrator privileges
do shell script "niutil -destroyval / /groups/appserveradm users " & localName with administrator privileges
do shell script "niutil -destroyval / /groups/appserverusr users " & localName with administrator privileges
do shell script "niutil -destroyval / /groups/admin users " & localName with administrator privileges
do shell script "nicl . -delete /groups/" & localName with administrator privileges
do shell script "niutil -destroyprop / /users/" & localName & " _shadow_passwd" with administrator privileges
do shell script "niutil -destroyprop / /users/" & localName & " gid" with administrator privileges
do shell script "niutil -destroyprop / /users/" & localName & " uid" with administrator privileges
do shell script "niutil -destroyprop / /users/" & localName & " realname" with administrator privileges
do shell script "niutil -destroyprop / /users/" & localName & " shell" with administrator privileges
do shell script "niutil -destroy / /users/" & localName with administrator privileges
 
set netID to text returned of (display dialog "Verify the Network ID is correct" default answer localName)
 
if netID is not equal to false then
	do shell script "mv /Users/" & localName & ".backup /Users/" & netID with administrator privileges
	do shell script "id " & netID
	do shell script "chown -R " & netID & " /Users/" & netID with administrator privileges
	display dialog netID & " has been converted to a domain account"
else if netID is equal to false then
	display dialog "Operation cancelled"
end if
Bookmark and Share

No related posts.

AD Integration, Automation, Mac, Scripting

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

10 Responses to “Convert Local Account’s Home to AD account with Local Home”

Leave Comment

(required)

(required)