' Declarations strComputer = "." ' Open connection to SQL strQuery = "SELECT A.ArchiveName, T.SID FROM Archive A, Trustee T, Root R WHERE A.RootIdentity = R.RootIdentity AND R.OwningTrusteeIdentity = T.TrusteeIdentity" ' Execute Query wscript.echo strquery Const adOpenStatic = 3 Const adLockOptimistic = 3 Set objConnection = CreateObject("ADODB.Connection") Set objRecordset = CreateObject("ADODB.Recordset") objConnection.Open "Driver={SQL Server};server=evault1;Database=EnterpriseVaultDirectory;Trusted_Connection=yes" objRecordset.Open strQUery, objConnection If objRecordset.EOF Then Wscript.Echo "Record cannot be found." wscript.quit end if Do while not objRecordSet.Eof ' Process results strSid = objRecordSet("SID") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objSID = objWMIService.Get("Win32_SID='" & strSID & "'") if objSID.AccountName <> "" then WScript.Echo objRecordSet("ArchiveName") & " - " & objRecordSet("SID") & " - " & objSID.ReferencedDomainName & "\" & objSID.AccountName else wscript.echo objRecordSet("ArchiveName") & " - " & objRecordSet("SID") & " - " & "** Unknown **" end if objRecordSet.MoveNext Loop ' Tidy up objRecordset.Close objConnection.Close