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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPS; need to shut down several servers when power fails 1

Status
Not open for further replies.

itopman

IS-IT--Management
Mar 23, 2004
20
0
0
GB
Hi..Please can you help I need to shut down serveral servers when the power fails from the UPS connected server, It allows a file to be run before it shuts its self down.

Can any one help..
 
Code:
'==========================================================================
'
' NAME: RebootWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/6/2004
'
' COMMENT: Reads a file WSLIST ands shuts down computers 
'          listed in the file.
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
	Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.ShutDown()
 		next
Next

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Mark this looks ideal (I think not knowing any thing about scripting) will give it a test, is their any location that the wslist.txt should be located. I do not see a path in the script.

The path the UPS software users to run a file is C:\Program Files\APC\PowerChute Business Edition\agent\cmdfiles\ This is were the shutdown.bat file will be located to execute the script do I just place it in the same location alone with this script?

cheer's
Brian
 
Mark, Ran a test with placing the files in the dirctory stated, shutdown 2 of the four servers in text file. I used the netbios names, updated this with the FQDN on the 2 servers that failed to shut down but still not working.

I placed a msgbox to show the output of each server name this seem to run fine. Any suggestion why the other 2 servers would not shut down.

one of the servers is a windows 2000 sp4 running SQL, the other is a FE OWA server on windows 2003 platform hich is on a DMZ.

Cheers
Brian
 
First off you figured out where to put the files right, I like to leave the path out because the script will automatically look in the same directory that it is run in. I find this easiest for quick testing but you could alter the path in the script if you wanted to specify another location.

As for the servers that did not reboot, check the local Group Policy on them. There is a setting under:

Computer Configuration
-Windows Settings
--Local policies
---User Rights Assignment
----Force Shutdown From a Remote System

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I have just checked the servers that did not shut down their local policy is assinged for administrators, which is the same rights as the ones that shut down successfully.

What right should be applied for this script to work because if they are the same then it must be something else right!

Cheer's
Brian
 
That would have been my only guess. Can you ping those servers by name?

There is one more thing you can try. Run this script on them to set the WSH Remote Scripting setting.

Code:
'==========================================================================
'
' NAME: EnableRemote.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 6/24/2003
'
' COMMENT: Enables remote scripting
'==========================================================================

Const HKEY_LOCAL_MACHINE = &H80000002

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close

For Each strWorkstation In RemotePC


Set objRegProv = GetObject("winmgmts:{impersonationLevel=Impersonate}" & _
                 "!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
objRegProv.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Remote","1"

Next

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Did you check out installing the PowerChute software on the other servers? Some editions of the PowerChute software would operate in a master / slave type of setup. It has been a while since I worked with it but you would either set up the UPS connected PowerChute to send messages to the other PowerChute clients or set the clients to check the status on the main. Since you have a Business Edition you may already have the proper software and license to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top