Server Management - Systems Insight Manager
1748180 Members
4041 Online
108759 Solutions
New Discussion юеВ

Re: scripting question

 
Seth Kelly
Advisor

scripting question

Well, I've been writing VBscripts that play with active directory and WMI for quite a while now, so I'm thinking it can't be all that hard to write one for SIM. So far, though, I haven't been having much luck.

I'm trying to write an ordinarily very simple script that will become a custom command to reboot a list of servers. I want to do some late-night unassisted reboots. It doesn't have to pull the list from the targets in SIM, it could read in a text file, but it would be nice to pull the list from SIM.

Here's the basic functionality of the code:
DO
Set CompConn = GetObject("winmgmts:{(RemoteShutdown)}//" & targetcomp & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

FOR EACH OS IN CompConn
OS.reboot()
NEXT
LOOP WHILE(boxes.atendofstream = false)

Can anyone give me some guidance as to how I might mod this simple function to run as a useful SIM custom command?

Thank you,
Seth
5 REPLIES 5
Seth Kelly
Advisor

Re: scripting question

Let me make that code a bit more intuitive, I didn't clean it up completely before posting it...

FOR EACH box IN somecomputerlist
Set CompConn = GetObject("winmgmts:{(RemoteShutdown)}//" & targetcomp & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

FOR EACH OS IN CompConn
OS.reboot()
NEXT
NEXT
Tim McGue
Regular Advisor

Re: scripting question

Seth,

I am attaching a script that will provide the functionality of reading through a list of computers and either reboot, logoff, or shut them down.

Now for the integration into SIM we might see if one of the HP guys that monitor this newsgroup might have some ideas.

Tim
Seth Kelly
Advisor

Re: scripting question

Thanks Tim. I appreciate the script. I do have scripts of my own that are relatively equivalent though. My main issue comes with making it convenient and useful to others. I'm just a summer intern, so much of the coding I do is focused on ease of use and long-term functionality for the real employees in my group who are less talented in coding.

My hope is that I can make this reboot server script work just like the identify systems tool in SIM, for example. To do that I need to understand how SIM interacts with my script.

If I run a custom command on server1, server2, and server3, how do I access that list of target servers in the script that the command executes? How do I report the results back to SIM? When I run the command on a list of servers, does it run the script locally on each server, or does it just execute in the location that I drop the script on my CMS? Basically, I'd like to know what the heck happens when I run a custom command and how I can harness those happenings. So far my experimentation hasn't been getting me anywhere.

If anyone has a script that is integrated similarly, that would probably be a less time-consuming alternative to explaining the inner workings of SIM to me. I realize this is a rather complex question, and very much appreciate any assistance.
Seth
Mark Kempe
Advisor

Re: scripting question

Hello Seth

I have had success by creating a custom command that launches my vb scripts when certain events come in. My script does not recieve a list of servers from SIM but it does recieve all of the variables that are stored in an event. SIM uses the variable DEVICENAME for the computername. I incorporate this into my script like this:

Set objShell = WScript.CreateObject("WScript.Shell")
strComputer = objShell.ExpandEnvironmentStrings("%DEVICENAME%")


Hope this helps
David Claypool
Honored Contributor

Re: scripting question

Bumped to be above moved questions...