jskfan
asked on
Redirect output to a file with VBScript
I have this script below that retrieve the computers in each OU of my domain
I would like to add filesystemobject code to put the output to the file instead of the screen.
any help?
Thanks
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Sea rchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=mydomain,dc=com ' WHERE " & _
"objectCategory='organizat ionalUnit' "
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objOU = GetObject(objRecordSet.Fie lds("ADsPa th").Value )
Wscript.Echo objOU.distinguishedName
objOU.Filter = Array("Computer")
For Each objItem in objOU
Wscript.Echo " " & objItem.CN
Next
Wscript.Echo
Wscript.Echo
objRecordSet.MoveNext
Loop
I would like to add filesystemobject code to put the output to the file instead of the screen.
any help?
Thanks
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.Properties("Pag
objCommand.Properties("Sea
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=mydomain,dc=com
"objectCategory='organizat
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objOU = GetObject(objRecordSet.Fie
Wscript.Echo objOU.distinguishedName
objOU.Filter = Array("Computer")
For Each objItem in objOU
Wscript.Echo " " & objItem.CN
Next
Wscript.Echo
Wscript.Echo
objRecordSet.MoveNext
Loop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Kool That you, Sometimes I am in a hurry and write on the fly leaving me carless of redability. I apperciate it
ASKER
I have an OU before the Domain Controllers OU and has compuers in it, I don't know why the script skips it and doesn't show the computers in it.
By the way it would be better if the script shows computers that are in containers too, instead of OUs only.
Sorry I should have mentioned that first time. I relaized that we have some containers that are not OUs and have computers inside.
Thanks
By the way it would be better if the script shows computers that are in containers too, instead of OUs only.
Sorry I should have mentioned that first time. I relaized that we have some containers that are not OUs and have computers inside.
Thanks
Since this question is about redirecting output, I think that's best left to a new question...
Is the redirecting of the output resolved for you?
Is the redirecting of the output resolved for you?
ASKER
it works fine now. the only thing missing is to tweak the script to show the computers in containers that are not OUs
And that should really be placed in a new question...
EE prefers that multiple questions not be asked in the same thread as it devalues the PAQ (question/answer database).
For instance, someone looking on how to search multiple OUs & containers for computers would not locate that information in this thread, were it answered here....
EE prefers that multiple questions not be asked in the same thread as it devalues the PAQ (question/answer database).
For instance, someone looking on how to search multiple OUs & containers for computers would not locate that information in this thread, were it answered here....
ASKER
No problem Sirbounty.....
Welcome back
Welcome back
To go through an OU with subs you will need recursion to Get a container set the class you are looking for is "container"
I just typically keep my declarations and assignments on the same line (just personal preference really)...
Open in new window