Imagine you have a domain full of computers at a school that has not been maintained for ages. Now you have a week to clean up 100 computers and you really don't want to go sit down at each one, figure out who uses it regularly and then clean up the cruft.
Enter delprof from the windows 2003 resource kit. Thanks MS.
It has its quirks. Case sentitive flags (for windows?!?!?!?) and MS resolution has to work. Otherwise Wooot. It just works.
Cygwin or a cronjob on my linux box give me all the systems, er victims, I need. This is one I use to shut down the school (with exceptions) at 7PM.
#! /bin/bash
# Gather the DHCP leases
rm /tmp/shutdown-ips
touch /tmp/shutdown-ips
for DHCPSERV in ADS-prime ADS-second
do
winexe --user DOMAIN\\admin --password=password --uninstall //${DHCPSERV} \
"netsh dhcp server \\\\${DHCPSERV} scope 10.10.10.0 show clients" \
| grep 10.10.10 | grep D | grep -v INAC | awk '{print $1}' >> /tmp/shutdown-ips
done
# Get the names of our victims
rm /tmp/shutdown-hosts
touch /tmp/shutdown-hosts
for IPADDR in `cat /tmp/shutdown-ips`
do
nslookup $IPADDR
done \
| grep name | awk '{print $4}' | cut -f 1 -d . | sort -u \
| egrep -iv 'savin|clr-|soq-|sqsr|sqto|Teacher-LT2|TeacherLT-3|smiley|ed-director' >> /tmp/shutdown-hosts
## Automated shutdown exclusions ##
# Printers - savin
# Printers - clr-
# Printers - soq-
# Printers - sqsr Soqel Staff Rm
# Printers - sqto Soqel Teachers Office
# Build a script
rm /tmp/sd-script.bat
touch /tmp/sd-script.bat
PRE='start shutdown /f /m \\\\'
POST=" /t 300 /s /c \"Automatic 7PM shutdown. To abort click start then run and type shutdown -a\""
for HOST in `cat /tmp/shutdown-hosts`
do
echo "${PRE}${HOST}${POST}" >> /tmp/sd-script.bat
done
# Shut them down
cp /home/hasbtech/psexec.exe /tmp
cd /tmp
unix2dos /tmp/sd-script.bat
smbclient -A /home/hasbtech/.authfile //tbs-second/c$ -c 'cd temp;put sd-script.bat;put psexec.exe'
cd -
Friday, July 3, 2009
Subscribe to:
Posts (Atom)