Nlcollings
Technical User
I need to be able to export a list of recipient policies from AD with the following fields: cn,msExchPolicyOrder,purportedSearch,gatewayProxy,disabledGatewayProxy
I used csvde prior to this and it worked well however i now need to be able to format the output so have decided to use VBS.
Here is the code i am using:
When i run the script the first 3 values are returned however when it tries to echo the disabledGatewayProxy value it returns a "type mismatch" error i believe this is due to the disabledGatewayProxy attribute containing multiple values.
I appoligise if my code is not displayed correctly, this is the first time i have posted
Thanks in advance for any replies
I used csvde prior to this and it worked well however i now need to be able to format the output so have decided to use VBS.
Here is the code i am using:
Code:
'on error resume next
'Open Output File
'set oFSO = wscript.Createobject("scripting.filesystemobject")
'set writeouttofile = oFSO.Opentextfile("c:\bds\output.txt", 8, True)
'Find LDAP Path
Set ObjRoot = GetObject("LDAP://RootDSE")
strConfigNC = ObjRoot.Get("configurationNamingContext")
Set colExchangeContainer = GetObject ("LDAP://CN=Microsoft Exchange,CN=Services," & strConfigNC)
If Err = 0 Then
For Each objExchangeOrg In colExchangeContainer
If (objExchangeOrg.Class = "msExchOrganizationContainer") Then
orgname = "CN=Recipient Policies," & objExchangeOrg.Get("distinguishedName")
End If
Next
Else
End If
'LDAP Variables
strADsPath = "<LDAP://" & orgname & ">;"
strFilter = "(purportedSearch=*);"
strAttrs = "cn,msExchPolicyOrder,purportedSearch,disabledGatewayProxy;"
strScope = "SubTree"
'Open Database connection
set objConn = CreateObject("ADODB.Connection")
objConn.Open "provider=ADsDSOObject;"
Set objADCommand = CreateObject("ADODB.Command")
objADCommand.ActiveConnection = objConn
objADCommand.CommandText = strADsPath & strFilter & strAttrs & strScope
Set objADRecordSet = objADCommand.Execute
'Read Data
objADRecordSet.Movefirst
while not objADRecordSet.EOF
For i = 0 to 3
wscript.echo objADRecordSet.fields(i).Name & "=" & objADRecordSet.fields(i).Value
'varname = objADRecordSet.fields(i).Name
'varvalue = objADRecordSet.fields(i).value
'wscript.echo varname & " - " & varvalue
'Output to file
'writeouttofile.Writeline varname & " - " & varvalue
next
objADRecordSet.movenext
Wend
objADRecordSet.close
Set objADRecordSet = Nothing
When i run the script the first 3 values are returned however when it tries to echo the disabledGatewayProxy value it returns a "type mismatch" error i believe this is due to the disabledGatewayProxy attribute containing multiple values.
I appoligise if my code is not displayed correctly, this is the first time i have posted
Thanks in advance for any replies