User profile script

Anyone to explain what this script does? I guess it is about user profiles, but need to understand what it does.

Thank you
================================

$_=SetOption("WrapAtEOL", "ON")
Break ON

 


$UserLDAP=OtherADObject ("sAMAccountName="+@userid)
$ComputerLDAP=OtherADObject("name="+@wksta)
$ComputerName=getObject($ComputerLDAP[0])
$UserObj=getObject($UserLDAP[0])

if not inGroup("CP_FolderRedirect") and not instr ($UserLDAP[0],"ou=UK") and not instr($UserLDAP[0],"ou=San Diego") and instr ($userobj.homedirectory,"szuserdata")

	if instr ($UserLDAP[0],$ComputerName.managedby) and $ComputerName.managedby<>"" and instr ($ComputerName.operatingSystem,"Professional")
		
		$MyMusicFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Music")
		$MyVideoFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Video")
		$MyPicturesFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures")
		$MyDocFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
		
		$FolderUpdate=0
		if instr ($MyMusicFolder,$UserObj.Homedirectory) or $MyMusicFolder="" or instr ($MyMusicFolder,"My Documents")
			if $MyMusicFolder<>""
				shell 'cmd /c \\Mydomain.corp\NETLOGON\HQ\Scripts\robocopy "'+$MyMusicFolder+'" "%userprofile%\My Music" /move /e /w:0 /r:0'
			else
				md "%userprofile%\My Music"
			endif
			
			$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Music","%userprofile%\My Music","REG_SZ")
			$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","My Music",CHR(37)+"USERPROFILE"+CHR(37)+'\My Music',"REG_EXPAND_SZ")
			$MyMusicFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Music")
			if instr ($MyMusicFolder,"%userprofile%\My Music")
				$FolderUpdate=1
					$changed="Music"
			endif
		endif
			
		if instr ($MyVideoFolder,$UserObj.Homedirectory) or $MyVideoFolder="" or instr ($MyVideoFolder,"My Documents")
			if $MyVideoFolder<>""
				shell 'cmd /c \\Mydomain.corp\NETLOGON\HQ\Scripts\robocopy "'+$MyVideoFolder+'" "%userprofile%\My Video" /move /e /w:0 /r:0'
			else
				md "%userprofile%\My Video"
			endif
			
			$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Video","%userprofile%\My Video","REG_SZ")
			$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","My Video",CHR(37)+"USERPROFILE"+CHR(37)+'\My Video',"REG_EXPAND_SZ")
			$MyVideoFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Video")
			if instr ($MyVideoFolder,"%userprofile%\My Video")
				$FolderUpdate=1
					$changed="videos"
			endif
		endif
			
		if isLaptop(@wksta)
		
			if not exist ("%userprofile%\My Documents")
				md "%userprofile%\My Documents"
			endif

			if not instr ($MyPicturesFolder,"\My Documents\My Pictures") and exist ("%userprofile%\My Documents")
				if $MyPicturesFolder=""
					md "%userprofile%\My Documents\My Pictures"
				endif
			
				$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures","%userprofile%\My Documents\My Pictures","REG_SZ")
				$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","My Pictures",CHR(37)+"USERPROFILE"+CHR(37)+'\My Documents\My Pictures',"REG_EXPAND_SZ")
				$MyPicturesFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures")
;				if instr ($MyPicturesFolder,"My Documents\My Pictures")
;					$FolderUpdate=1
;					$changed="Pics"
;				endif
			endif
			
			if instr ($MyDocFolder,$UserObj.Homedirectory)
				if not exist ("%userprofile%\My Documents")
					md "%userprofile%\My Documents"
					md "%userprofile%\My Documents\My Pictures"
				endif
				$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal","%userprofile%\My Documents","REG_SZ")
				$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","Personal",CHR(37)+"USERPROFILE"+CHR(37)+'\My Documents',"REG_EXPAND_SZ")
				if $MyDocFolder<>ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","Personal")
					$FolderUpdate=1
				endif
					
				if exist ("%userprofile%\My Documents.lnk")
					del "%userprofile%\My Documents.lnk"
				endif
					
				if exist ("%userprofile%\Do Not Use. My Documents moved to H drive") and exist ("\\szuserdata\userdata$\"+@userid)
					if not exist ("\\szuserdata\userdata$\"+@userid+"\Profile")
						md "\\szuserdata\userdata$\"+@userid+"\Profile"
					endif
						
					if not exist ("\\szuserdata\userdata$\"+@userid+"\Profile\"+@wksta)
						md "\\szuserdata\userdata$\"+@userid+"\Profile\"+@wksta
					endif
						
					shell 'cmd /c \\Mydomain.corp\NETLOGON\HQ\Scripts\robocopy "%userprofile%\Do Not Use. My Documents moved to H drive" "\\szuserdata\userdata$\'+@userid+'\Profile\'+@wksta+'" /move /e /w:0 /r:0'
				endif
				
				
			endif
						
		else ; Deskops
		
			if not instr ($MyPicturesFolder,$userobj.homedirectory) and instr ($MyDocFolder,$userobj.homedirectory)
			
				if $MyPicturesFolder=""
					md $userobj.homedirectory+"\My Pictures"
				endif
			
				$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures",$userobj.homedirectory+"\My Pictures","REG_SZ")
				$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","My Pictures",$userobj.homedirectory+"\My Pictures","REG_EXPAND_SZ")
				$MyPicturesFolder=ReadValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures")
;				if instr ($MyMusicFolder,$userobj.homedirectory+"\My Pictures")
					$FolderUpdate=1
;				endif
				
			endif

			if instr ($MyDocFolder,"Documents and Settings") and instr ($Userobj.homedirectory,"szuserdata")
;				if exist ($userobj.homedirectory) and instr ($userobj.homedirectory,"MyDoc")
				if not exist ($userobj.homedirectory+"\My Pictures")
					md $userobj.homedirectory+"\My Pictures"
				endif
				
				$_=WriteValue("HKU\"+@SID+"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal",$userobj.homedirectory,"REG_SZ")
				$_=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","Personal",$userobj.homedirectory,"REG_EXPAND_SZ")
				if $MyDocFolder<>ReadValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell FOlders","Personal")
					$FolderUpdate=1
				endif
;				endif
			endif
		endif
		
	else
		?"User is not the owner of this computer."
	endif
	
else
	?"User is a member of folder redirect or a UK or a SD user"
endif




if $folderUpdate=1
	$Answer=messagebox("Your My Documents/My Music/My Video folder has been moved to your local drive and requires a restart before you can use it.  Click OK to restart now or cancel to continue working.  "+$changed,"My Doc redirection disabled",1)
	
	if $Answer=1
		$_=shutdown(@wksta,"Restarting Now",0,1,1)
	endif

endif

Open in new window

jskfanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThomasMcA2Commented:
If the user is not in the CP_FolderRedirect group, and not in the UK or San Diego, and the user running the script owns the computer, and the running version of Windows contains "Prefessional", then the script moves a server-based My Documents/My Music/My Video folder to the local drive. It uses RoboCopy to copy the documents from the server path to the local path.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
I would also suggest determining if this is a process you want your company to have and whether the user should have their profile copied to the computer if they are not the owner.

Further to what's already been said, this checks Active Directory and whether the current user running the script has been associated with the AD computer account as the owner of that computer.
0
jskfanAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.