Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Line Arguements and combining into an all in one.

Status
Not open for further replies.

raven47172

Technical User
Aug 14, 2010
1
US
I need these scripts to accept command line arguements and also to be combined into an all-in-one script after they have been changed to accept command line arguements. I do not know how to do either so help would be greatly appreciated.

'* Example Script: Create a User Account

'* precondition: assumes userid does NOT already exists in Active Directory

'* Declare constants to be used in script
Const ADS_UF_ACCOUNTDISABLE = 2

'* set up 4 string variables
userid = "ForinashK"
lastName = "Forinash"
firstName = "Kyle"
useridLC = LCase(userid)

'* Note: the 4th variable (above) 'useridLC' contains a lowercase value of the user id

'* obtain access to the Marketing OU
Set objOU = GetObject("LDAP://ou=Marketing,dc=bailiwick,dc=local")

'* create a new user inside the Marketing OU

Set objUser = objOU.Create("User", "cn=" & userid)
objUser.Put "sAMAccountName", useridLC
objUser.SetInfo

'* Set Name Information

objUser.Put "sn", lastName
objUser.Put "givenName", firstName
objUser.Put "displayName", firstName & " " & lastName
objUser.SetInfo

'* Enable Account - by default the account gets created as '* "unabled", this "enables" it

intUAC = objUser.Get("userAccountControl")
objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
objUser.SetInfo

'* Exit script
Wscript.Quit

-----------------------------------

'* Example Script: Create a User's Folder

'* precondition: user's folder does NOT already exist on the file server

'* set up 2 string variables

userid = "ForinashK"
folderName = "F:\USERS\" & userid

'* Important Note: the 2nd variable (above) is created by
'* concatenating 2 strings together using & operator

'* Obtain access to the file system
Set objFSO = CreateObject("Scripting.FileSystemObject")

'* Create User's folder using the file system object

Set objFolder = objFSO.CreateFolder(folderName)

'* Exit script

Wscript.Quit

---------------------------------

'* Example Script: To give a user Full access rights to their own folder

'* precondition: assumes userid is already created and in Active Directory and
'* user's folder has already been created on the file server

'* set up 2 string variables

userid = "ForinashK"
newuserLC = LCase(userid)

'* Obtain access to the to shell object

set objShell = CreateObject("Wscript.Shell")

'* Use the shell object to start up Command Line (i.e., that the %COMSPEC% variable used below)
'* Use "cacls" command to give access rights of user to new folder

objShell.Run "%COMSPEC% /c Echo Y| cacls \\A247Server\users\" & newuserLC & " /c /e /g " & newuserLC & ":F", 2, True

'* Important Note: the & operator is used multiple times in the line above
'* for concatentation, creating a very long string

'* Note:
'* To get help info for "cacls" command, start up a Command Prompt and type "cacls /?"

'* Exit script

Wscript.Quit

---------------------------------

'* Example Script: Connect user account in Active Directory to Home Folder

'* precondition: assumes userid already exists in Active Directory

'* set up 2 string variables
userid = "ForinashK"
useridLC = LCase(userid)
'* obtain access to user object

Set objUser = GetObject("LDAP://cn=ForinashK,ou=Marketing,dc=bailiwick,dc=local")

'* set the user's homefolder information on the Profile tab

objUser.Put "homeDrive", "H:"
objUser.Put "homeDirectory", "\\A247Server\users\" & useridLC
objUser.SetInfo

'* Exit script

Wscript.Quit

Again any help would be greatly appreciated.
 
Have a look at the WScript.Arguments collection.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top