for (( i=0; i < "${#wks[@]}"; i++)); do
net rpc SHUTDOWN -C "This system was left on after hours and is being shutdown" -f -I "${wks[$i]}" -U user_name%password
done"
Basically what the script does is scans the network(s) with nmap, pipes it though grep and cut to get the FQDN. Then "grep -v -f serverlist" is an exclude list of server I don't want shutdown. From there it puts the workstations into an array and turns off each system.
def shutdown(host=None, user=None, passwrd=None, msg=None, timeout=0, force=1,
reboot=0):
""" Shuts down a remote computer, requires NT-BASED OS. """
# Create an initial connection if a username & password is given.
connected = 0
if user and passwrd:
try:
win32wnet.WNetAddConnection2(win32netcon.RESOURCET YPE_ANY, None,
''.join([r'\\', host]), None, user,
passwrd)
# Don't fail on error, it might just work without the connection.
except:
pass
else:
connected = 1
# We need the remote shutdown or shutdown privileges.
p1 = win32security.LookupPrivilegeValue(host, win32con.SE_SHUTDOWN_NAME)
p2 = win32security.LookupPrivilegeValue(host,
win32con.SE_REMOTE_SHUTDOWN_NAME)
newstate = [(p1, win32con.SE_PRIVILEGE_ENABLED),
(p2, win32con.SE_PRIVILEGE_ENABLED)]
# Grab the token and adjust its privileges.
htoken = win32security.OpenProcessToken(win32api.GetCurrent Process(),
win32con.TOKEN_ALL_ACCESS)
win32security.AdjustTokenPrivileges(htoken, False, newstate)
win32api.InitiateSystemShutdown(host, msg, timeout, force, reboot)
# Release the previous connection.
if connected:
win32wnet.WNetCancelConnection2(''.join([r'\\', host]), 0, 0)