General help and info provided by Helewix.com Webmasters
| « Manage Local Groups using VBS | Determine the SCHEMA MASTER FSMO holder in your Forest » |
The following script will:
1. Check your File and Print server to make sure that the user has got a home folder created on \\ServerName\userdata$\ using the usrName that we have declared in the first part of the code.
2. If the folder does not exist it will create the following folders:
a. Create a folder using the username
b. Now we will create a folder called "My Documents" inside the Username folder and for the purpose of this test we will also create and additional folder called "Personal Data"
3. Next it will assign rights to the user (Modify Rights) and Domain Admins (Full Control)
4. Now after the server side has been sorted, we can start creating shortcuts to the shares on the users desktop
5. Ones again we will first check to see if the folder already exist on the user's Desktop, if not we will create it with the shortcuts.
6. If the previous script identified no documents on the user's desktop it will create a folder called "Company Documents"
7. Inside this folder it will create 2 shortcuts, one that points directly to the "My Documents" on the server and the other pointing to the "Personal Data"
You can also download the code below. Please let me know if this helped, any feedback will be appreciated.
Dim objFSO, objFolder, strDirectory, WshS, WSHSell, intRunError, objShell, strUser
Set WshS = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'Expand Environment
'Create const's to spare time and place
usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")
usrName = WshS.ExpandEnvironmentStrings("%UserName%")
' Message to prove my string contains the path to my profile
strProfilepath = usrProfile
' CREATE FOLDERS ON USER SHARE IF IT DOES NOT EXIST AND ASSIGN RIGHTS
strDirectory = "\\ServerName\userdata$\" & usrName
'WScript.Echo "username is " & strDirectory
' Create FileSystemObject. So we can apply .createFolder method
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.CreateFolder(strDirectory)
Set objFolder = objFSO.CreateFolder(strDirectory & "\My Documents")
Set objFolder = objFSO.CreateFolder(strDirectory & "\Personal Data")
End If
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDirectory) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strDirectory & " /t /c /g " & usrName & ":C ""Domain Admins"":F", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " & strUser & " to home folder " & strDirectory
End If
End If
' CREATE FOLDER AND LINKS ON USERS DESKTOP
strDirectory = strProfilepath & "\Desktop\Company Documents"
' Create FileSystemObject. So we can apply .createFolder method
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strProfilepath & "\Desktop\Company Documents") Then
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
' WScript.Echo "Just created " & strDirectory
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
strLink = strDesktop & "\Company Documents" & "\My Documents.lnk"
set oShellLink = WshShell.CreateShortcut(strLink)
oShellLink.TargetPath = "\\ServerName\userdata$\%username%\My Documents"
oShellLink.Description = "My Documents"
oShellLink.WorkingDirectory = "\\ServerName\userdata$\%username%\My Documents"
oShellLink.Save
strLink2 = strDesktop & "\Company Documents" & "\Personal Data.lnk"
set oShellLink2 = WshShell.CreateShortcut(strLink2)
oShellLink2.TargetPath = "\\ServerName\userdata$\%username%\Personal Data"
oShellLink2.Description = "Personal Data"
oShellLink2.WorkingDirectory = "\\ServerName\userdata$\%username%\Personal Data"
oShellLink2.Save
Download Script: Helewix.com - CreateFolders-and-Links