Problems with script - Critique please??? 
Author Message
 Problems with script - Critique please???

    Here is my would be quick and dirty user adder.  It keeps giving me an
error when trying to set the users drive letter for home drive.  Can someone
please tell me what I am doing wrong?  I am getting pretty frustrated with
this damn thing...  It does everything I need except for disable the TS
logon on the user account...  When i run the script from primalscript, I get
the following error:
C:\Documents and Settings\rrinehar\Desktop\qdusers.vbs(81, 1) (null):
Unspecified error
I have entered the property value every way I can think of.  I was trying to
use "HomeDirDrive" but kept getting errors with it also.  I thought that
writing these ADSI scripts would be a walk in the park to learn.  It turns
out I am VERY wrong...

Thanks,
Ryan

option Explicit

Dim objDomain, objThisDomain, objUser, objOU, objOUpath, objContainer,
objRegExp
Dim sUsername, sFullName, sDescription, sPassword, sHomeDrive, alpha
Dim sHomeDirectory, sProfilePath, sProfileFlag, sPrefix, sLogin, sHomeDir,
sprofile, sUserHomeDrive

'set properties for new account
sUsername = InputBox("Please enter the users SAM account Name.","Enter Logon
Name","username")
sFullName = InputBox("Please enter the users Full Name.","Enter Full
Name","User Name")
sDescription = InputBox("Please enter the users Description.","Enter User
Description","Employee")
sProfileFlag = MsgBox("Does this user get a roaming profile?", vbYesNo +
vbQuestion, "Does User Need Roaming Profile?")
'obtain OU to create user in
objOU = InputBox("Please enter the Organizational Unit the user will be
in.","Enter User OU","Users")
sPassword = "genericpassword"
sPrefix = "LDAP://"
sLogin = "dofa.bat"

'Set Home Directory & profile paths Based on Username input
If IsAtoL(sUsername) Then
 sHomeDir = "\\server\share\a-l\" & sUsername
 sProfilePath = "\\server\share\a-l\" & sUsername & "\profile"
 Else
 sHomeDir = "\\servername\share\m-z\" & sUsername
 sProfilePath = "\\servername\share\m-z\" & sUsername & "\profile"
End If
If (Err.Number <> 0) Then
  BailOnFailure Err.Number, "on HomeDir and Profile Path"
End If

'bind to domain - Call function
BindDomain
objThisDomain = BindDomain

'Set Home Directory Drive Letter Based on OU input
sUserHomeDrive = GetHomeDriveMap(objOU)
WScript.Echo "" & sUserHomeDrive
'specify the OU to add user to
objOUpath = "OU=" & objOU & ",OU=Divisions," & objThisDomain

' Create the new user account
Set objContainer = GetObject(sPrefix & objOUpath)
If (Err.Number <> 0) Then
  BailOnFailure Err.Number, "on GetObject method"
End If

Set objUser = objContainer.Create("user", "CN=" & sFullName)
If (Err.Number <> 0) Then
  BailOnFailure Err.Number, "on Create User method"
End If

objUser.Put "samAccountName", sUsername
objUser.SetInfo

objUser.SetInfo
objUser.AccountDisabled=false
objUser.SetInfo
objUser.SetPassword(sPassword)
objUser.SetInfo
objUser.Put "Description", sDescription
objUser.SetInfo
objUser.LoginScript = sLogin
objUser.SetInfo
objUser.Put "HomeDirectory", sHomeDir
objUser.SetInfo
'set profile path if answered yes to need a profile
If sprofileflag = vbYes Then
objUser.Profile=sProfilePath
objUser.SetInfo
End If
objUser.HomeDrive=sUserHomeDrive
objUser.SetInfo

'=====================================
'section for subroutines
'=====================================
Sub BailOnFailure(ErrNum, ErrText)    strText = "Error 0x" & Hex(ErrNum) & "
" & ErrText
    MsgBox strText, vbInformation, "ADSI Error"
    WScript.Quit
End Sub

'=========================================
'section for functions
'=========================================

'function determines if username is A-L or M-Z
Function IsAtoL(sUsername)
'** Filter a first letter of user name string.
 alpha = Left(sUsername, 1)
'create regular expression to determine naming scheme
 Set objRegExp = New RegExp
 objRegExp.IgnoreCase = True
'** Proper regexp syntax for this case.
 objRegExp.Pattern = "[A-L]"
'use regular expression to test username
 IsAtoL = objRegExp.Test(alpha)
End Function

'function binds to current domain
Function BindDomain()
 Set objDomain = GetObject ("LDAP://rootDSE")
 If (Err.Number <> 0) Then
  BailOnFailure Err.Number, "on RootDSE --> GetObject method"
End If

 BindDomain = objDomain.Get ("defaultNamingContext")
 If (Err.Number <> 0) Then
  BailOnFailure Err.Number, "on Get --> Default Naming method"
End If
End Function

'Function for determining Home Directory Drive Mapping
Function GetHomeDriveMap(argOU)
 Select Case(argOU)
  Case "AD"
  sHomeDrive = "H:"
  Case "AH"
  sHomeDrive = "H:"
  Case "AP"
  sHomeDrive = "H:"
  Case "AR"
  sHomeDrive = "F:"
  Case "BD"
  sHomeDrive = "F:"
  Case "BS"
  sHomeDrive = "F:"
  Case "BT"
  sHomeDrive = "H:"
  Case "BU"
  sHomeDrive = "H:"
  Case "CS"
  sHomeDrive = "H:"
  Case "DI"
  sHomeDrive = "F:"
  Case "FM"
  sHomeDrive = "H:"
  Case "GO"
  sHomeDrive = "H:"
  Case "LG"
  sHomeDrive = "H:"
  Case "OB"
  sHomeDrive = "H:"
  Case "PE"
  sHomeDrive = "F:"
  Case "PU"
  sHomeDrive = "H:"
 End Select
GetHomeDriveMap = sHomeDrive
End Function

'** End Script



Wed, 15 Dec 2004 01:51:28 GMT  
 Problems with script - Critique please???
    OK, I needed to trim the input and use lcase.  I changed the gethomedir
function to specify lowercase names and then used lcase to force my input to
lowercase.  Now it works!!!  Guess I just needed to relax and take another
look at it later...  Now I just need to figure out how to disable the users'
ability to logon to terminal server.

R

Quote:
>     Here is my would be quick and dirty user adder.  It keeps giving me an
> error when trying to set the users drive letter for home drive.  Can
someone
> please tell me what I am doing wrong?  I am getting pretty frustrated with
> this damn thing...  It does everything I need except for disable the TS
> logon on the user account...  When i run the script from primalscript, I
get
> the following error:
> C:\Documents and Settings\rrinehar\Desktop\qdusers.vbs(81, 1) (null):
> Unspecified error
> I have entered the property value every way I can think of.  I was trying
to
> use "HomeDirDrive" but kept getting errors with it also.  I thought that
> writing these ADSI scripts would be a walk in the park to learn.  It turns
> out I am VERY wrong...

> Thanks,
> Ryan

> option Explicit

> Dim objDomain, objThisDomain, objUser, objOU, objOUpath, objContainer,
> objRegExp
> Dim sUsername, sFullName, sDescription, sPassword, sHomeDrive, alpha
> Dim sHomeDirectory, sProfilePath, sProfileFlag, sPrefix, sLogin, sHomeDir,
> sprofile, sUserHomeDrive

> 'set properties for new account
> sUsername = InputBox("Please enter the users SAM account Name.","Enter
Logon
> Name","username")
> sFullName = InputBox("Please enter the users Full Name.","Enter Full
> Name","User Name")
> sDescription = InputBox("Please enter the users Description.","Enter User
> Description","Employee")
> sProfileFlag = MsgBox("Does this user get a roaming profile?", vbYesNo +
> vbQuestion, "Does User Need Roaming Profile?")
> 'obtain OU to create user in
> objOU = InputBox("Please enter the Organizational Unit the user will be
> in.","Enter User OU","Users")
> sPassword = "genericpassword"
> sPrefix = "LDAP://"
> sLogin = "dofa.bat"

> 'Set Home Directory & profile paths Based on Username input
> If IsAtoL(sUsername) Then
>  sHomeDir = "\\server\share\a-l\" & sUsername
>  sProfilePath = "\\server\share\a-l\" & sUsername & "\profile"
>  Else
>  sHomeDir = "\\servername\share\m-z\" & sUsername
>  sProfilePath = "\\servername\share\m-z\" & sUsername & "\profile"
> End If
> If (Err.Number <> 0) Then
>   BailOnFailure Err.Number, "on HomeDir and Profile Path"
> End If

> 'bind to domain - Call function
> BindDomain
> objThisDomain = BindDomain

> 'Set Home Directory Drive Letter Based on OU input
> sUserHomeDrive = GetHomeDriveMap(objOU)
> WScript.Echo "" & sUserHomeDrive
> 'specify the OU to add user to
> objOUpath = "OU=" & objOU & ",OU=Divisions," & objThisDomain

> ' Create the new user account
> Set objContainer = GetObject(sPrefix & objOUpath)
> If (Err.Number <> 0) Then
>   BailOnFailure Err.Number, "on GetObject method"
> End If

> Set objUser = objContainer.Create("user", "CN=" & sFullName)
> If (Err.Number <> 0) Then
>   BailOnFailure Err.Number, "on Create User method"
> End If

> objUser.Put "samAccountName", sUsername
> objUser.SetInfo

> objUser.SetInfo
> objUser.AccountDisabled=false
> objUser.SetInfo
> objUser.SetPassword(sPassword)
> objUser.SetInfo
> objUser.Put "Description", sDescription
> objUser.SetInfo
> objUser.LoginScript = sLogin
> objUser.SetInfo
> objUser.Put "HomeDirectory", sHomeDir
> objUser.SetInfo
> 'set profile path if answered yes to need a profile
> If sprofileflag = vbYes Then
> objUser.Profile=sProfilePath
> objUser.SetInfo
> End If
> objUser.HomeDrive=sUserHomeDrive
> objUser.SetInfo

> '=====================================
> 'section for subroutines
> '=====================================
> Sub BailOnFailure(ErrNum, ErrText)    strText = "Error 0x" & Hex(ErrNum) &
"
> " & ErrText
>     MsgBox strText, vbInformation, "ADSI Error"
>     WScript.Quit
> End Sub

> '=========================================
> 'section for functions
> '=========================================

> 'function determines if username is A-L or M-Z
> Function IsAtoL(sUsername)
> '** Filter a first letter of user name string.
>  alpha = Left(sUsername, 1)
> 'create regular expression to determine naming scheme
>  Set objRegExp = New RegExp
>  objRegExp.IgnoreCase = True
> '** Proper regexp syntax for this case.
>  objRegExp.Pattern = "[A-L]"
> 'use regular expression to test username
>  IsAtoL = objRegExp.Test(alpha)
> End Function

> 'function binds to current domain
> Function BindDomain()
>  Set objDomain = GetObject ("LDAP://rootDSE")
>  If (Err.Number <> 0) Then
>   BailOnFailure Err.Number, "on RootDSE --> GetObject method"
> End If

>  BindDomain = objDomain.Get ("defaultNamingContext")
>  If (Err.Number <> 0) Then
>   BailOnFailure Err.Number, "on Get --> Default Naming method"
> End If
> End Function

> 'Function for determining Home Directory Drive Mapping
> Function GetHomeDriveMap(argOU)
>  Select Case(argOU)
>   Case "AD"
>   sHomeDrive = "H:"
>   Case "AH"
>   sHomeDrive = "H:"
>   Case "AP"
>   sHomeDrive = "H:"
>   Case "AR"
>   sHomeDrive = "F:"
>   Case "BD"
>   sHomeDrive = "F:"
>   Case "BS"
>   sHomeDrive = "F:"
>   Case "BT"
>   sHomeDrive = "H:"
>   Case "BU"
>   sHomeDrive = "H:"
>   Case "CS"
>   sHomeDrive = "H:"
>   Case "DI"
>   sHomeDrive = "F:"
>   Case "FM"
>   sHomeDrive = "H:"
>   Case "GO"
>   sHomeDrive = "H:"
>   Case "LG"
>   sHomeDrive = "H:"
>   Case "OB"
>   sHomeDrive = "H:"
>   Case "PE"
>   sHomeDrive = "F:"
>   Case "PU"
>   sHomeDrive = "H:"
>  End Select
> GetHomeDriveMap = sHomeDrive
> End Function

> '** End Script



Fri, 17 Dec 2004 23:45:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Critique this script please

2. Critique this script please

3. critique please - My new website

4. critique please

5. Critique these two scripts

6. Critique on Active Desktop script

7. PLEASE HELP: IE problems with support for VB scripting

8. Site Check please...problems with scripts

9. Login Script Problems: Please Help1

10. scripting problem - please help

11. Please help me with this HTML-Scripting problem

12. Looking for some critiquing

 

 
Powered by phpBB® Forum Software