Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
change service user's domain pw
Logged in as: Guest
arrSession:exec spGetSession 2,16,26915
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> change service user's domain pw
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
change service user's domain pw -
10/13/2005 8:33:48 AM
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status:
offline
ok last one :)
'========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1 ' ' NAME: Service User Change Password ' ' AUTHOR: Kirrilian ' Date : 2/22/2005 ' ' COMMENT: ' usage: cscript service_user.vbs account input_file.txt password. Password is optional. ' Account can be In these formats: username, domain\username, username@domain.com. The script will ' strip off the domain portions And only use the username to search. If you arent sure of the ' username you can use partial names To query. eg MOM will give hits on SA_MOM and MOM2 ' NOTE: if your password has special characters In it you will have To enclose it In quotes ' the input file should be a list of machines With one hostname per line you want to change the ' password on. The script will also change the domain password For the user. You will be prompted ' if youre sure you want to change the password for the service And AD. ' NOTE: For windows 2000 you have to enter the EXACT username as it is listed. '========================================================================== Set objArgs = WScript.Arguments.Unnamed Dim fso, strUserName, domain, chpw Set fso = CreateObject("Scripting.FileSystemObject") Set objUserDictionary = CreateObject("Scripting.Dictionary") Set objNameDictionary = CreateObject("Scripting.Dictionary") MyDate = Replace(Date, "/", "-") OutputFile = "./output-" & mydate & ".txt" If Not objArgs.Count = 0 Then If objArgs.Count = 3 Then user = WScript.Arguments.Item(0) Inputfile = WScript.Arguments.Item(1) password = WScript.Arguments.Item(2) If fso.FileExists(InputFile) Then Set txtStreamIn = fso.OpenTextFile(InputFile) Set txtStreamOut = fso.OpenTextFile(OutputFile, 2, True) Do While Not (txtStreamIn.AtEndOfStream) chpw = True strComputer = txtStreamIn.ReadLine 'printOut vbNewLine printOut "Starting run for " & strComputer printOut "********************************************" 'flyapart user getSvcOwner strComputer,user printOut vbNewLine Loop Else WScript.Echo "Input file doesnt exist." usage End If chADpw user,password Elseif objArgs.Count = 2 Then user = WScript.Arguments.Item(0) Inputfile = WScript.Arguments.Item(1) If fso.FileExists(InputFile) Then Set txtStreamIn = fso.OpenTextFile(InputFile) Set txtStreamOut = fso.OpenTextFile(OutputFile, 2, True) Do While Not (txtStreamIn.AtEndOfStream) strComputer = txtStreamIn.ReadLine chpw = False printOut "Starting run for " & strComputer printOut "********************************************" 'flyapart user getSvcOwner strComputer,user printOut vbNewLine Loop Else WScript.Echo "Input file doesnt exist." usage End If Else usage End If Else usage End If Sub getSvcOwner(strComputer,name) 'WScript.Echo strcomputer & name Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 'check for OS version *ugh* Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems WScript.Echo objOperatingSystem.Caption If InStr(objOperatingSystem.Caption, "2003") > 0 Then 'since win2k3 supports the 'like' keyword use it if possible flyapart name Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName like '%" & strUserName & "%'") Elseif InStr(objOperatingSystem.Caption, "2000") > 0 Then 'win2k doesnt support the 'like' keyword, dangit name = Replace(name, "\", "\\") Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName = '" & name & "'") Else Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName = '" & name & "'") End If Next If colServiceList.Count = 0 Then printOut "Search returned 0 hits." 'WScript.Quit Else For Each objService in colServiceList printOut "On computer " & strComputer & " Service " & objService.Name & " is owned by " _ & objService.Startname & "." Next If chpw = True Then chSVCpw strComputer,name,password End If End If End Sub 'getSvcOwner Sub chADpw(username,pw) 'AD pw change sure = MsgBox ("Change AD Password For " & username & " To " & pw & "?", 36, "Are you sure?")'52 If sure = 6 Then printOut vbNewLine printOut "Changing AD password For " & username & " To " & pw 'open AD connection here since it is used in several places Set objADConnection = CreateObject("ADODB.Connection") objADConnection.Open "Provider=ADsDSOObject;" Set objADCommand = CreateObject("ADODB.Command") objADCommand.ActiveConnection = objADConnection flyapart username 'WScript.Echo "using " & strUserName & " for query" objADCommand.CommandText = _ "<GC://dc=ent,dc=win2k3,dc=com>;(&((objectCategory=User)(sAMAccountName=" & strUserName & ")));"_ & "displayName,name,legacyExchangeDN,authorizeddomain,distinguishedName;subtree" Set objADRecordSet = objADCommand.Execute If objADRecordset.RecordCount = 0 Then WScript.Echo "AD Search returned 0 hits." Else name = objADRecordSet.Fields("name") dn = objADRecordSet.Fields("distinguishedName") End If Set objUser = GetObject _ ("LDAP://" & dn & "") objUser.SetPassword pw printOut "Password changed to " & pw & "." Else printOut "Not Changing AD password." End If End Sub 'chADpw sub chSVCpw(strComputer,user,password) 'use the hash tables to go back through the services on each server and change the password sure = MsgBox ("Change Service Password For " & user & " To " & password & " on " & strComputer & "?", 36, "Are you sure?") If sure = 6 Then Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 'check for OS version *ugh* Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems WScript.Echo objOperatingSystem.Caption If InStr(objOperatingSystem.Caption, "2003") > 0 Then 'since win2k3 supports the 'like' keyword use it if possible flyapart user Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName like '%" & strUserName & "%'") Elseif InStr(objOperatingSystem.Caption, "2000") > 0 Then 'win2k doesnt support the 'like' keyword, dangit name = Replace(name, "\", "\\") Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName = '" & user & "'") Else Set colServiceList = objWMIService.ExecQuery("Select StartName,Name from Win32_Service where StartName = '" & user & "'") End If Next ' Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where StartName like '%" & user & "%'") 'Set colServiceList = objWMIService.ExecQuery _ '("Select * from Win32_Service Where StartName = '" & user & "'") For Each objService in colServiceList printOut "Changing " & user & "'s password to " & password & " on " & strComputer & " for service " & objService.Name errReturn = objService.Change( , , , , , , , password) next Else printOut "Not Changing Service password." End If End Sub 'chSVCpw Sub usage() WScript.Echo "Usage: cscript service_user.vbs username input_file.txt password. Password is optional." & vbnewline _ & vbTab & "NOTE: if your password has special characters in it you will have to enclose it in quotes" & vbnewline _ & vbTab & "See the script header for more information." End Sub 'usage Sub printOut (data) WScript.Echo data txtStreamOut.writeline data End Sub 'printOut Function flyapart(input) 'breaks up email addys and domain logins of all types 'format = domain\username Or username@some.domain.com If InStr(input, "\") > 0 Then domain = lcase(Left(input, InStr(input, "\") - 1)) rmEmail = (Len(input)-InStr(input, "\")) strUserName = lcase(Right(input, rmEmail)) Elseif InStr(input, "@") > 0 Then rmEmail = (Len(input)-InStr(input, "@")+1) strToReplace = Right(input, rmEmail) quickArray = Split(strToReplace, ".") strUserName = LCase(Replace(input, strToReplace, "")) domain = LCase(Replace(quickarray(0), "@", "")) Else strUserName = input End If End Function 'flyapart
_____________________________
Have you searched
here
?
VBScript Fundamentals
My Site
Post #: 1
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
Post a VBScript
>> change service user's domain pw
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI