1

我正在寻找一个vbscript可以将计算机帐户“成员”中的所有组放到文本文件中的方法。对于要复制到文本中的“成员”用户帐户,我使用 net user test 命令,我将在几秒钟内/domain c:\temp\testaccount.txt获得所有成员或Local/Global组成员身份的详细信息。是否有要运行的命令或是否需要脚本?

梅尔文

4

1 回答 1

0

这是我使用的脚本,但这永远不会像您的控制台命令那样运行得那么快,如果这是一个问题,您可以使用运行命令从脚本执行命令。您需要知道您的域的 LDAP 路径。由于回显,您最好使用 cscript.exe 运行它。

Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
Dim fso, filename, objConnection, objCommand, oShell, sResult, objRecordSet, oFile_out
Set fso = CreateObject("Scripting.FileSystemObject")
filename = "\\server\share\out.txt"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://domain/OU=Workstations,OU=Computers,...>;;name;subtree"
Set oShell = CreateObject("Wscript.Shell")
sResult = oShell.Popup("Generating list..", 2, "Have some patience please, the list is generated")
on error resume next
Set objRecordSet = objCommand.Execute
Call CheckForError
set oFile_out = fso.OpenTextFile (filename, ForWriting, CreateIfNeeded)
Call CheckForError
While Not objRecordset.EOF
  oFile_out.writeline objRecordset.Fields("name")
  Wscript.Echo objRecordset.Fields("name")
  objRecordset.MoveNext
Wend
'--- ---'
Sub CheckForError
  if err.number <> 0 Then
    msgbox("39: "&err.description)
    err.clear
  end if
End Sub
于 2012-11-23T08:36:43.317 回答