Page 1 of 1 1
Topic Options
#165750 - 2006-08-10 06:04 PM Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
We have a major upgrade to a software application that we need to push some software out using a Group Policy. The problem is that we have several users that do not shut their computers down and we'd like to be able to do it remotely.

I have started a script that uses the UDF's NetView2, Ping, and ComputerInGroup. I've used NetView2 & Ping in the past to successfully stop and start the Trend Micro listening service on any computer that was on the domain and was powered on. I can modify that script to shutdown all computers but I need to be able to shutdown everything but the servers.

Which is where the ComputerInGroup comes into play. The problem I'm having is that I don't fully understand how I would add this into the script to only shutdown computers that ping and are not in the group.

So my thought was this:
Code:
FOR EACH $Computer In NetView2(@ldomain)
IF $Computer
IF PING($Computer,0) AND ComputerInGROUP('SERVERS') = 0
SHUTDOWN ($Computer,"Your Computer is being shutdown to install an application", 45, FORCE)
ENDIF
ENDIF
NEXT

Exit



Unfortunately this did not work as I thought it would so any quidence would be appreciated. I've used different parts of the code seperatly successfully but when I try to get them together in one script it's not so great, I ended up shutting down everything in my test domain.

Thanks in advance - JTT

Top
#165751 - 2006-08-10 06:37 PM Re: Shutdown all worstations in a domain remotely
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
IMHO, ComputerInGROUP() only works for the computer the function is running on. There is no parameter to specify a computername.
Top
#165752 - 2006-08-10 06:57 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
That makes sense, I guess I got too excited when I found the ComputerInGroup function as I saw it as a way to resolve my issue. I honestly wasn't thinking that my firsts tests were against the machine I was running the script on.

I'll do some more digging to see if there is anything that would allow me to exclude all the servers I want to exclude. If anyone has some ideas or could point me in a direction to look I would much apprecaite it.

Top
#165753 - 2006-08-10 07:22 PM Re: Shutdown all worstations in a domain remotely
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe you can create an array of the objects in the group "servers" and check against each of them... Or if the list of servers is not too long, just quickly write the list yourself
Top
#165754 - 2006-08-10 07:29 PM Re: Shutdown all worstations in a domain remotely
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Assuming the servers are in a different OU, you could use a modified version of Howard's InContainer() UDF as I do to ascertain. I tried to get Howard to modify his UDF to allow for a different name as a parm but I don't recall him ever posting an update.
Top
#165755 - 2006-08-10 07:37 PM Re: Shutdown all worstations in a domain remotely
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Inversely, you could use fnLDAPQuery() http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=141262 to select only those OUs you want to action.
Top
#165756 - 2006-08-10 08:01 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
Thanks for the input I will definetly look at those as I've found the few UDF's I've used in the past to be very useful and educational. Is is possible to use the AScan() with an array I type in with the @wksta macro or would this fail too because I'm not running this on the machines I want to shut down?

I'm going to go head the FAQ's and read the documentation again for a refresher. Thanks again

Top
#165757 - 2006-08-10 08:12 PM Re: Shutdown all worstations in a domain remotely
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
@WkSta applies only to the computer running the script, not the intended target. You can however populate an array and use AScan() to search the array.
Top
#165758 - 2006-08-10 08:18 PM Re: Shutdown all worstations in a domain remotely
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe InContainer() can modified very easy. Just replace @wksta by $workstation and add $workstation to the parms...
[Edit]
Yep Les, I see you suggested it
[/Edit]


Edited by Witto (2006-08-10 08:24 PM)

Top
#165759 - 2006-08-10 10:58 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
Ok, I had to walk away from this for a minute because my brain is in overload. I've read through your posts and I think the easiest would be to create the array of all our servers, I have to compile a list anyway if I want to move them to containers seperate containers, then use the IsInArray UDF to see if there's a match and if there's not issue the command.

So with the UDF's NetView2, Ping, and IsInArray run this code:
Code:
$SERVERS = 'server1','server2','server3, 'etc'
FOR EACH $Computer In NetView2(@ldomain)
IF $Computer
IF PING($Computer,0) AND IsInArray($Servers,$Computer)=0
SHUTDOWN ($Computer,"Your Computer is being shutdown to install an application", 45, FORCE)
ENDIF
ENDIF
NEXT

Exit


Top
#165760 - 2006-08-10 11:02 PM Re: Shutdown all worstations in a domain remotely
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
No need for the IsInArray UDF. Kix has AScan build in that will do the trick in your case. See page 57 and 58 in the manual for the details on AScan.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165761 - 2006-08-10 11:13 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
Thanks
I believe this is bascially what the other two were saying but since my brain isn't functioning properly today I didn't catch on. So instead of what I had previously I'd just use this:

Code:
$SERVERS = 'server1','server2','server3', 'etc'
FOR EACH $Computer In NetView2(@ldomain)
IF $Computer
IF PING($Computer,0) AND AScan($Servers,$Computer)= -1
SHUTDOWN ($Computer,"Your Computer is being shutdown to install an application", 45, FORCE)
ENDIF
ENDIF
NEXT

Exit



This should enumerate the domain using the NetView2, then if the computer Pings and is not in the array I create with my servers it should receive a shutdown command.

Top
#165762 - 2006-08-10 11:28 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
Just wanted to say thanks again for all the input. With that last bit of code I pasted I ran and it worked great. Thanks again.
Top
#165763 - 2006-08-11 12:01 AM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
On this same subject, it appears the Shutdown built into kix will not allow for a shutdown of a locked machine. Can I shell out the Windows Shutdown to force locked workstations to shutdown? And if so how would I pass the $Computer variable into the shelled out command?

Thanks again.

Top
#165764 - 2006-08-11 12:11 AM Re: Shutdown all worstations in a domain remotely
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
There are a number of tools on the Internet for such tasks.
There is also a more robust one with Server 2003

This is a nice tool as well.


POWEROFF
http://users.pandora.be/jbosman/applications.html

Top
#165765 - 2006-08-11 12:42 AM Re: Shutdown all worstations in a domain remotely
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Or just the Shutdown.exe that can be found on your computer.
Top
#165766 - 2006-08-11 02:44 AM Re: Shutdown all worstations in a domain remotely
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
The easiest answer.... On the side of the building there should be a big lever on a gray box that has large pipes leading in and out of it.....

Ok, it might be considered an RGE but still could be fun...

Resume
Generating
Event

Top
#165767 - 2006-08-11 02:53 AM Re: Shutdown all worstations in a domain remotely
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Our (office) computers that are not tied to the process all have a scheduled task that reboots them once a week. If we schedule a service window and users fail to comply, we reboot them with Hyena.
Top
#165768 - 2006-08-11 08:44 AM Re: Shutdown all worstations in a domain remotely
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
You can get all the computernames from the A.D.
In a script you can do something like
Code:

Shell "shutdown -f -s -m \\" + $computer + " -t 3"


You must however be a network administrator that has local administrator rights on the computers.

Top
#165769 - 2006-08-12 06:07 PM Re: Shutdown all worstations in a domain remotely
JTT Offline
Fresh Scripter

Registered: 2002-10-14
Posts: 32
Loc: Utah
Thanks for all the input. I did end up just using the shell command with the shutdown from a 2003 server and that worked for my needs this weekend for the upgrade.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.073 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org