VBS: Update Services Password on Local/Remote Box

This script, will allow you to update passwords for services that “Log on As” set to use a domain account.
You can download it here.
‘Written by Jase McCarty
‘Date: 03/29/2006


‘Description: Change the password on a local
‘or remote system for a Service that has
‘”Logon As” set for a Domain Account
‘Useful for Servers when a service account
‘has a password change
Option Explicit
Dim shellobj,env
Dim strUserDomain,strUserName,strPassword,strComputer
Dim CSComputerName,CSAccount,CSPassword,objWMIService
Dim objService
‘Check to make sure that we receive enough arguements (2 or more)
If Wscript.Arguments.Count < 2 Then



‘Create a Shell Object & be able to get environment variables
Set shellobj = CreateObject(“Wscript.Shell”)
Set env = shellobj.Environment(“process”)

‘Setup default domain for credentials
‘(could be modified to be an attribute)
strUserDomain = env(“USERDOMAIN”)
strUserName = Wscript.Arguments(0)
strPassword = Wscript.Arguments(1)

‘Check to make sure we have enough arguements (2 or more)
If Wscript.Arguments.Count > 2 Then
‘If we 3, then the Computername will be the 3rd arguement
strComputer = Wscript.Arguments(2)
‘If we only receive the first 2, then the Computername
‘will be the local computer
strcomputer = env(“COMPUTERNAME”)
End If

‘Call the ChangeServices subroutine
Call ChangeServices(strComputer,strUserDomain & “” & strUserName,strPassword)


End If

‘The ChangeServices SubRoutine
‘This requires a computername, account,and password to be passed to it
Sub ChangeServices(CSComputerName,CSAccount,CSPassword)

‘Setup a WMIService object, and setup a query to put all services in an array
Set objWMIService = GetObject(“winmgmts:\” & CSComputerName & “rootcimv2”)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_Service”,,48)

‘Loop through the array
For Each objService in colItems

‘If the “Logon As” of the current service matches the user specified,
‘change the password to the one specified
If Lcase(objService.StartName) = LCase(CSAccount) Then
‘Make the credentials change
errReturn = objService.Change(,,,,,,CSAccount,CSPassword)

‘Write to the screen and the computer’s event log, the success or failure
If err.number <> 0 then
shellobj.LogEvent 1,”Failure Changing Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
Wscript.Echo “Failure Changing Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
shellobj.LogEvent 0,”Successfully Changed Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
Wscript.Echo “Successfully Changed Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
End If

End If


End Sub

Read more

VMware: Backing up your ESX Configuration/VMX files

This is a quick/easy/down/dirty way of backing up your ESX configuration information.

You’ll need to add a cron job, and create a script to run that cron job.

Here’s the script that I used to mount a Windows share, copy the files over, and then unmount the Windows share (I saved it in /root as backup.sh:
mount -t smbfs //windowsserver/sharename /mountpoint -o username=user/DOMAIN,password=password

cd /mountpoint/ESX_Backups/

rm -rf ./old.$HOSTNAME/

mv ./$HOSTNAME/ ./old.$HOSTNAME/


cd /

cp -duR /etc/ /mountpoint/ESX_Backups/$HOSTNAME/

cp -duR /home/ /myappro/ESX_Backups/$HOSTNAME/

umount /mountpoint
For this to work properly, in your Windows share, you will already need to have a folder named ESX_Backups (it is case sensitive).

You’ll need to figure out where you mount point is going to be, where you can mount the Windows share to.

Also, make sure you do a chmod 700 backup.sh so this file will be executable.

By copying all files in /etc/ and /home/ I get all ESX config files, and VM config files. You could modify this to be more specific, but I didn’t see the need to. I like the KISS method.

Now I made a cron entry like this:
10 23 * * * * root /root/backup.sh > /dev/null 2>&1
And saved it as /etc/cron.d/backupcron.sh, with a chmod 500 for it.

Simple, effective, & very little time to implement. And now I have the past 2 days worth of ESX and VM config.

Read more

VMware: Full path in ESX 2.5/3.0 Service Console

This is an old post, but I redid the blog…
Not sure how many of you use PuTTY and the COS, but I figured I’d post this tidbit.

I got tired of looking at just
[root@host log]# for my prompt.
Showing only my current directory

I would rather have
[root@host /var/log]#
Which shows the full path

You can modify the /etc/bashrc file ( back it up first!!!) to change this.

Look for this line in the /etc/bashrc file:
[ “$PS1” = “\s-\v\$ ” ] && PS1=”[u@h W]\$ “

Change it to:
[ “$PS1” = “\s-\v\$ ” ] &amp;& PS1=”[u@h w]\$ “

Notice the uppercase “W” became a lowercase “w”. Save the file and log off/log on. Look at your prompt. Now, I have no questions as to which directory I’m in.

Here’s a link to the original post: http://www.vmware.com/community/thread.jspa?messageID=211436&211436

Posted by Jase to Computer Stuff at 3/16/2006 02:19:11 PM

Read more