【问题标题】:VBS string wizzardryVBS 字符串魔法
【发布时间】:2009-07-29 00:53:59
【问题描述】:

好吧,不是这样,但是...

所以这是一个快速脚本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" Then),但没有产生任何结果。

那么,我如何过滤输出,以便只获取公共域上的地址?

【问题讨论】:

    标签: vbscript exchange-server


    【解决方案1】:

    替换

    If Not Alias = "*.lan"
    

    If Right(Alias, 4) <> ".lan"
    

    (它可以用正则表达式完成,但现在是星期五,我累了!)

    【讨论】:

      【解决方案2】:

      您可以使用正则表达式来过滤掉与您的条件不匹配的行。类似于以下内容。

      smtp:.*@publicdomain\.com
      

      或者,您也可以调整 LDAP 查询以仅返回特定 OU 的用户。是否有只有拥有 Exchange 帐户的用户才属于的 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
      

      【讨论】:

        猜你喜欢
        • 2011-09-30
        • 1970-01-01
        • 1970-01-01
        • 2013-02-08
        • 1970-01-01
        • 1970-01-01
        • 2012-06-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多