Vbscript 字符串wizzardry
好吧,所以不是,但是 这是一个在我的Exchange服务器上运行的快速脚本,它转储了一个电子邮件地址列表,我可以用它在垃圾邮件过滤器上验证收件人:Vbscript 字符串wizzardry,vbscript,exchange-server,Vbscript,Exchange Server,好吧,所以不是,但是 这是一个在我的Exchange服务器上运行的快速脚本,它转储了一个电子邮件地址列表,我可以用它在垃圾邮件过滤器上验证收件人: ' Export all valid recipients (= proxyAddresses) into a ' file virtual.txt ' ' Ferdinand Hoffmann & Patrick Koetter ' 20021100901 ' Shamelessly stolen from ' http://www.mi
' 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”那么),但没有产生任何结果
那么,如何过滤输出,以便只获取公共域上的地址呢?您可以使用正则表达式过滤掉不符合条件的行。类似下面的内容
smtp:.*@publicdomain\.com
或者,您也可以调整LDAP查询,使其仅返回特定OU的用户。是否存在仅具有exchange帐户的用户所属的广告组
这是用于正则表达式匹配的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
替换
If Not Alias = "*.lan"
与
如果正确(别名,4)“.lan”
(这可以用正则表达式完成,但今天是星期五,我累了!)
If Right(Alias, 4) <> ".lan"