WMI: Scripting DSQUERY to report FSMO roles using an Array
So while Friday's effort got the job done, Saturday's effort is a more compact and efficient way of doing the same thing using a 1-dimensional array. Instead of building each command separately, and then building the output, you can do all of that effort with one for-next loop. Granted, the display of the output could be improved a bit, but this will do nicely as a function in my inventory script. One thing you'll need to keep in mind is that when working with an array, you need to start counting at 0, such that "ArrFSMOCmds(4)" has 5 values (0,1,2,3,4).
Dim objShell, ArrFSMOCmds(4)
Set objShell = CreateObject("WScript.Shell")
Cmd1 = "cmd /c"
Cmd2 = "dsquery server -hasfsmo "
ArrFSMOCmds(0) = "schema"
ArrFSMOCmds(1) = "rid"
ArrFSMOCmds(2) = "name"
ArrFSMOCmds(3) = "infr"
ArrFSMOCmds(4) = "PDC"
For Each ArrFSMOCmds in ArrFSMOCmds
Set objExec = objShell.Exec(Cmd1 & Cmd2 & ArrFSMOCmds)
strExecResults = LCase(objExec.StdOut.ReadAll)
Wscript.Echo ArrFSMOCmds & ": " & strExecResults
Next
No comments:
Post a Comment