好的,所以不是,但是......
所以这是一个快速脚本I found on the internet,它在我的Exchange服务器上运行并转储一个电子邮件地址列表,我可以用它来在垃圾邮件过滤器上进行收件人验证:
' Export all valid recipients (= proxyAddresses) into a
' file virtual.txt
'
' Ferdinand Hoffmann & Patrick Koetter
' 20021100901
' Shamelessly stolen from
' http://www.microsoft.com/windows2000/techinfo/ \
' planning/activedirectory/bulksteps.asp
'Global variables
Dim Container
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("virtual.txt", True)
Set Container=GetObject("LDAP://CN=Users,DC=office,DC=example,DC=com")
'Enumerate Container
EnumerateUsers Container
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set Container = Nothing
'Say Finished when your done
WScript.Echo "Finished"
WScript.Quit(0)
'List all Users
Sub EnumerateUsers(Cont)
Dim User
'Go through all Users and select them
For Each User In Cont
Select Case LCase(User.Class)
'If you find Users
Case "user"
'Select all proxyAddresses
Dim Alias
If Not IsEmpty(User.proxyAddresses) Then
For Each Alias in User.proxyAddresses
OutPutFile.WriteLine "alias: " & Alias
'WScript.Echo Alias
Next
End If
Case "organizationalunit" , "container"
EnumerateUsers User
End Select
Next
End Sub
问题在于收件人列表如下所示:
smtp:user@local.lan
SMTP:user@publicdomain.com
x400:c=US;a= ;p=local;o=Exchange;s=lastname;g=firstname;
smtp:postmaster@publicdomain.com
smtp:webmaster@publicdomain.com
垃圾邮件过滤器有一个导入脚本,只导入前缀为“smtp”或“SMTP”的行,因此x400不是问题。问题是我不希望VBscript导出“user@local.lan”地址。我试过这个:
'List all Users
Sub EnumerateUsers(Cont)
Dim User
'Go through all Users and select them
For Each User In Cont
Select Case LCase(User.Class)
'If you find Users
Case "user"
'Select all proxyAddresses
Dim Alias
If Not IsEmpty(User.proxyAddresses) Then
For Each Alias in User.proxyAddresses
If Not Alias = "*.lan" Then
OutPutFile.WriteLine "alias: " & Alias
WScript.Echo Alias
End If
Next
End If
Case "organizationalunit" , "container"
EnumerateUsers User
End Select
Next
End Sub
但是,这没有任何作用。我尝试过匹配公共域(如果Alias =“ publicdomain ”那么)但是没有产生任何结果。
那么,我如何过滤输出,以便我只在公共领域获得地址?
答案 0 :(得分:1)
替换
If Not Alias = "*.lan"
与
If Right(Alias, 4) <> ".lan"
(可以用正则表达式完成,但是星期五,我累了!)
答案 1 :(得分:0)
您可以使用正则表达式过滤掉与您的条件不符的行。如下所示。
smtp:.*@publicdomain\.com
或者,您也可以调整LDAP查询以仅返回某个OU的用户。是否存在仅包含交换帐户的用户的AD组?
这是RegEx匹配的VBS ......
Dim s : s = "smtp:user@local.lan" & VBCRLF & _
"SMTP:user@publicdomain.com" & VBCRLF & _
"x400:c=US;a= ;p=local;o=Exchange;s=lastname;g=firstname;" & VBCRLF & _
"smtp:postmaster@publicdomain.com" & VBCRLF & _
"smtp:webmaster@publicdomain.com"
Dim ex : ex = "smtp:.*@publicdomain\.com"
Dim oRE: Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global = True
oRE.Pattern = ex
Dim matches : Set matches = oRE.Execute(s)
For Each match In matches
WScript.Echo match.Value
Next