Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export list of recipient policies from AD

Status
Not open for further replies.

Nlcollings

Technical User
Mar 12, 2008
2
GB
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:

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
 
Solved it and script is a lot more tidy.

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

Set recobj = GetObject ("LDAP://"&orgname)
If Err = 0 Then 
  For Each objrecpol In recobj
	outvari = ""
	newarr = objrecpol.GetEX("GatewayProxy")

	for each arrval In newarr
		outvari = outvari & " ~ " & arrval
	Next
    
	cnvari = objrecpol.Get("cn")
	ordervari = objrecpol.Get("msExchPolicyOrder")
	emailvari = outvari
	filtervari = objrecpol.Get("purportedSearch")


      wscript.echo ordervari & " --- " & cnvari & " --- " & filtervari & " --- " & emailvari
  
  Next
Else
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top