Jump to content

Shutting down domain PC's..


Recommended Posts

has anyone wrote a script to do this or something that could be modified to do this that they would like to share..?

Are you wanting to select a particular machine to shutdown or wanting to target a list of devices? Have you looked at psshutdown from Microsoft? It's free and is pretty simple to use.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

ive been looking at PSShutdown, it seems to be the prefered tool.

I want to use this tool but I want to basically shutdown all the machines on my network (that are not locked) at a specific time say 23:59.

I can get a list of machines which are switched on with the "NET view" command but this gives me servers etc which i dont want to shutdown. All my machines are in 2 OU's in Active directory. how can I easly create a txt file for PSShutdown from these OU's or from the NET View command filtering all the servers from the list..?

i didnt know if anyone has already do a filter for Active directory to assist PSShutdown.

Link to comment
Share on other sites

@all

This give you already a good lead.

dim $osObj, $osColl 
    const $nLogOff=0 
    const $nReboot=2 
    const $nForceLogOff=4 
    const $nForceReboot=6 
    const $nPowerDown=8 
    const $nForcePowerDown=12 

$osColl = Objget("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem") 

    For $osObj in $osColl
        $osObj.Win32Shutdown($nForcePowerDown$)
    Next

Enjoy !!

ptrex

Link to comment
Share on other sites

My servers and end user computers have distinctive netbios names. Its pretty easy for me to filter. I also pull lists from SMS collections. If you use SMS that is an option. Sorry, I don't do much with native Microsoft AD tools nor do I do much domain level scripting.

However, Script-o-matic from the Microsoft Scripting Guys probably has a script to dump the contents of an OU to a txt file. It just so happens that Script-o-matic has been written in AutoIT. If it doesn't help you today it certainly will come in handy sometime.

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

Can anyone help me here.

I have got this script which pulls all the computer names from within Active directory. how can I change this so it only looks in 2 OU's that i specify & not the domain root? Sorry for my ignarance here, I dont have a clue when it comes to VB.

const FileName ="Domain Computers.csv"

set cmd = createobject("ADODB.Command")

set cn = createobject("ADODB.Connection")

set rs = createobject("ADODB.Recordset")

cn.open "Provider=ADsDSOObject;"

cmd.activeconnection = cn

set objRoot = getobject("LDAP://RootDSE")

cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;(objectCategory=Computer);" & _

"name"

'**** Bypass 1000 record limitation ****

cmd.properties("page size")=1

set rs = cmd.execute

set objFSO = createobject("Scripting.FileSystemObject")

set objCSV = objFSO.createtextfile(FileName)

q = """"

while rs.eof <> true and rs.bof <> true

objcsv.writeline(q & rs("name") & q)

rs.movenext

wend

objCSV.Close

cn.close

wscript.echo "Finished"

Edited by chiners_68
Link to comment
Share on other sites

@chiners_68

This is the translation so far.

const $FileName ="Domain Computers.csv"

; Declare COM Object error handler:
Global $oComError = ObjEvent("AutoIt.Error", "_ComErrFunc")

$cmd = ObjCreate("ADODB.Command")
$cn = ObjCreate("ADODB.Connection")
$rs = ObjCreate("ADODB.Recordset")

$cn.open ("Provider=ADsDSOObject;")
$cmd.activeconnection = $cn

$objRoot = ObjGet("LDAP://RootDSE")

$cmd.commandtext = "<LDAP://" & $objRoot.get("defaultNamingContext") & ">;(objectCategory=Computer);" & _
"name"

;**** Bypass 1000 record limitation ****
$cmd.properties("page size")=1

$rs = $cmd.execute

;$objFSO = ObjCreate("Scripting.FileSystemObject")
;$objCSV = $objFSO.createtextfile($FileName)

$q = """"

$rs.moveFirst()

;while $rs.eof <> 1 and $rs.bof <> 1
;$objCSV.writeline($q (& $rs("name") & $q))
Do
    ConsoleWrite ($rs("name").value & @CRLF)
$rs.movenext()
until $rs.eof
;wend

;$objCSV.Close()
$cn.close()

ConsoleWrite ("Finished")

Func _ComErrFunc()
    Local $HexNumber = Hex($oComError.number, 8)
    MsgBox(16, "AutoIT COM Error Occured!", _
            @TAB & "Error Number: " & $HexNumber & @CRLF & _
            @TAB & "Line Number: " & $oComError.scriptline & @CRLF & _
            @TAB & "Description: " & $oComError.description & @CRLF & _
            @TAB & "WinDescription: " & $oComError.windescription)
    SetError(1); something to check for when this function returns
EndFunc   ;==>_ComErrFunc

regards,

ptrex

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...