Re: Reading From txt file - newbie
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Nov 2008 08:18:30 -0600
"gbrown135" <gbrown135@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:138003B7-4C15-4BC4-AD5C-CB5CEC3CC561@xxxxxxxxxxxxxxxx
Hi
I have a script that remove's the Profile, Home and Terminal Services
attribute's/info. At the moment it prompt's for a username. I now need
this
to run so I can point it to a txt file and it can read the name's from
there
rather than from a Prompt. Can anyone please help? The script I have at
the
moment is below:
Option Explicit
Const ForReading = 1
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_PROPERTY_CLEAR = 1
dim strUser, strDomain, strUserDN
dim objTrans, objUser
strUser = InputBox("Enter User Name")
strDomain = "Globalinfra"
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strUser
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.PutEx ADS_PROPERTY_CLEAR, "homeDrive", 0
objUser.SetInfo
objUser.PutEx ADS_PROPERTY_CLEAR, "homeDirectory", 0
objUser.SetInfo
objUser.PutEx ADS_PROPERTY_CLEAR, "profilePath", 0
objUser.SetInfo
objUser.PutEx ADS_PROPERTY_CLEAR, "userParameters", 0
objUser.SetInfo
wscript.echo "H, Profile and Terminal Services Cleared"
Use the FileSystemObject to read a text file. For example:
=======
Option Explicit
Const ForReading = 1
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_PROPERTY_CLEAR = 1
dim strUser, strDomain, strUserDN
dim objTrans, objUser
Dim strFile, objFSO, objFile
' Specify the file of user names.
strFile = "c:\scripts\users.txt"
' Specify domain.
strDomain = "Globalinfra"
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Read the file one line at a time.
Do Until objFile.AtEndOfStream
strUser = Trim(objFile.ReadLine)
' Skip blank lines.
If (strUser <> "") Then
' Use Set method to specify NT name.
' Trap error if user not found.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strUser
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "User " strUser & " not found"
Else
On Error GoTo 0
' Retrieve user Distinguished Name
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to user object and clear properties.
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.PutEx ADS_PROPERTY_CLEAR, "homeDrive", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "homeDirectory", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "profilePath", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "userParameters", 0
' Save changes.
objUser.SetInfo
End If
End If
Loop
' Clean up.
objFile.Close
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- Reading From txt file - newbie
- From: gbrown135
- Reading From txt file - newbie
- Prev by Date: Re: Calling Executable from VBScript
- Next by Date: Re: Weird script issues
- Previous by thread: Reading From txt file - newbie
- Next by thread: Calling Executable from VBScript
- Index(es):
Relevant Pages
|
Loading