#165750 - 2006-08-10 06:04 PM
Shutdown all worstations in a domain remotely
|
JTT
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
|
|
|
|
#165752 - 2006-08-10 06:57 PM
Re: Shutdown all worstations in a domain remotely
|
JTT
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
|
|
|
|
#165756 - 2006-08-10 08:01 PM
Re: Shutdown all worstations in a domain remotely
|
JTT
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
|
|
|
|
#165759 - 2006-08-10 10:58 PM
Re: Shutdown all worstations in a domain remotely
|
JTT
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
|
|
|
|
#165761 - 2006-08-10 11:13 PM
Re: Shutdown all worstations in a domain remotely
|
JTT
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
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
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
   
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
|
|
|
|
#165768 - 2006-08-11 08:44 AM
Re: Shutdown all worstations in a domain remotely
|
Arend_
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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|