Announcement

Collapse
No announcement yet.

Public Folder

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Public Folder

    Does anyone know the right code to get all public fodlers in a Windows 2003 Exchange environment...I found this, but it doesn't work:

    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & _
            "\ROOT\MicrosoftExchangeV2")
    
    Set colItems = objWMIService.ExecQuery _
        ("Select * from Exchange_PublicFolder")
    Thanks to anyone who can help...what I need back from it is the foldername and an email address if there is one attached to it.

  • #2
    Re: Public Folder

    Does anyone know how to do this?

    Comment


    • #3
      Re: Public Folder

      It worked fine for me....
      Code:
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & _
              "\ROOT\MicrosoftExchangeV2")
      
      Set colItems = objWMIService.ExecQuery _
          ("Select * from Exchange_PublicFolder")
      
      For Each Folder in colItems
      
         Wscript.Echo Folder.name
      
      
      Next
      Regards,
      Jeremy

      Network Consultant/Engineer
      Baltimore - Washington area and beyond
      www.gma-cpa.com

      Comment


      • #4
        Re: Public Folder

        Originally posted by ekrengel View Post
        Does anyone know how to do this?
        Worked for me too. Don't mean to be Captain Obvious here but you need to run this from the Exchange machine with a privileged account for it to work.
        Andrew

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment


        • #5
          Re: Public Folder

          Oh...I wasn't using "Folder.name." That works...I was using:
          Code:
          For Each objItem in colItems
            Wscript.Echo objItem.name
          Actually you don't have to run it from the Exchange machine...I'm on my normal workstation and it works fine now...you just need the exchange rights. So for the email address it would be...

          Code:
          Wscript.Echo Folder.TargetAddress
          ?

          Comment


          • #6
            Re: Public Folder

            You can't get the email address through WMI. You'll need to use ADSI.

            This link should help you in doing that.
            http://gsexdev.blogspot.com/2006/09/...-based-on.html

            Also, I don't know why your test didn't work... objItem is just as good a variable as Folder.
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment


            • #7
              Re: Public Folder

              Yeah I don't know why either...But I'm going to stick with this because it's working. Yeah the TargetAddress just gives me back the path of where the folder is in exchange...I will take a look at that link. Thanks.

              Comment


              • #8
                Re: Public Folder

                Nope, no emailadddresses can be found here;

                Code:
                strComputer = "."
                Set objWMIService = GetObject("winmgmts:" _
                    & "{impersonationLevel=impersonate}!\\" & strComputer & _
                        "\ROOT\MicrosoftExchangeV2")
                
                Set colItems = objWMIService.ExecQuery _
                    ("Select * from Exchange_PublicFolder")
                
                For Each Folder in colItems
                If Folder.IsMailEnabled=TRUE then Wscript.Echo Folder.getObjectText_
                Next

                You have to use a LDAP query in AD to find emailaddresses.
                You can use ActiveDirectory Users and Computers / "Saved Queries" to get the list of only mailEnabled PublicFolders. Then use 'Add columns' to view the emailadresses.

                Now what you can do is to copy the query code from that saved query and use this LDAP string in a vbscript:

                Code:
                ' PublicFolders.vbs
                ' Remco Simons [nl] 2007
                ' http://forums.petri.com/showthread.php?t=16667
                
                strComputer = "."
                Set objWMIService = GetObject("winmgmts:" _
                    & "{impersonationLevel=impersonate}!\\" & strComputer & _
                        "\ROOT\MicrosoftExchangeV2")
                
                Set colItems = objWMIService.ExecQuery _
                    ("Select * from Exchange_PublicFolder")
                
                For Each PFolder in colItems
                  strProxyAddresses = "IsMailEnabled= False"
                  strDisplayName = PFolder.AddressBookName
                  strSecondary = Empty : Secondary = Empty
                  If PFolder.IsMailEnabled=TRUE then
                    strProxyAddresses = GetProxies(strDisplayName)
                  End If
                
                If Len(Secondary) Then strSecondary = "[ "& Secondary &" ]"&vbNewLine
                  Wscript.Echo "PublicFolder: "& strDisplayName & vbNewLine & _
                               strProxyAddresses & vbNewLine & strSecondary
                Next
                
                wscript.quit
                
                
                Function GetProxies(AddressBookName)
                   on error resume next
                   Primary = ""
                   Secondary =  ""
                   Set rootDSE = GetObject("LDAP://RootDSE")
                   DomainContainer = rootDSE.Get("defaultNamingContext")
                
                   Set conn = CreateObject("ADODB.Connection")
                   conn.Provider = "ADSDSOObject"
                   conn.Open "ADs Provider"
                
                   ldapStr = "<LDAP://" & DomainContainer & ">;(&(&(&(&" &  _ 
                     "(| (objectCategory=publicFolder) )))(objectCategory=publicFolder)" & _
                     "(displayName="& AddressBookName &")));adspath;subtree"
                
                   Set rs = conn.Execute(ldapStr)
                
                   Set oPublicFolder = GetObject(rs.Fields(0).Value)
                
                   Err.Clear
                   For each email in oPublicFolder.proxyAddresses
                   If Err.number then Exit For
                       If Left(email,5) = UCase("SMTP:") Then
                            Primary = "Primary e-mail address: " & Mid (email,6)
                            'Exit For
                       ElseIf Left(email,5) = LCase("smtp:") Then
                          Secondary =  Mid (email,6) & "; " & Secondary
                       End If
                   Next
                   If Err.number then _
                   Primary = "Primary e-mail address: " & Mid (oPublicFolder.proxyAddresses,6)
                
                   GetProxies = Primary
                
                End Function
                This way you have all the Public Folders even the Not-MailEnables ones, and you have all the emailaddresses of the folders that are MailEnabled.

                \RemS

                - Scripting Exchange Using VBScript and ADSI (Part 1)
                - Scripting Exchange Using VBScript and ADSI (Part 2)
                - Scripting Exchange Using VBScript and ADSI (Part 3)
                Last edited by Rems; 27th June 2007, 23:50. Reason: Typo -> now changed to: Err.Clear

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: Public Folder

                  Rems,

                  You are my idol lol...you always have the answer. Once again, thank you. Here's my end result with the script, added the excel portion which you have also showed me. Thanks again.

                  Code:
                  strComputer = "."
                  strFile = "C:\Documents and Settings\ekrengel\Desktop\Public Folder Script\Public Folders.xls"
                  Set objWMIService = GetObject("winmgmts:" _
                      & "{impersonationLevel=impersonate}!\\" & strComputer & _
                          "\ROOT\MicrosoftExchangeV2")
                  
                  Set colItems = objWMIService.ExecQuery _
                      ("Select * from Exchange_PublicFolder")
                  
                  Set objExcel = CreateObject("Excel.Application")
                  objExcel.Visible = False
                  objExcel.Workbooks.Add
                  objExcel.Cells(1,1).Value = "All Public Folder in Domain "
                  objExcel.Cells(1,1).Font.Bold = True
                  objExcel.Cells(1,1).Font.Size = 13
                  objExcel.Cells(1,1).Interior.ColorIndex = 11
                  objExcel.Cells(1,1).Interior.Pattern = 1 'xlSolid 
                  objExcel.Cells(1,1).Font.ColorIndex = 2
                  objExcel.Cells(1,1).Borders.LineStyle = 1 '= xlSolid
                  objExcel.Cells(1,1).WrapText = True
                  
                  objExcel.Cells(2,1).Value = "Time: " & Now
                  objExcel.Cells(2,1).Font.Bold = True
                  objExcel.Cells(2,1).Font.Size = 12
                  objExcel.Cells(2,1).Interior.ColorIndex = 11 
                  objExcel.Cells(2,1).Interior.Pattern = 1 'xlSolid 
                  objExcel.Cells(2,1).Font.ColorIndex = 2
                  objExcel.Cells(2,1).Borders.LineStyle = 1 '= xlSolid
                  objExcel.Cells(2,1).WrapText = True
                  
                  objExcel.Cells(4,1).Value = "Folder Name"
                  objExcel.Cells(4,1).Font.Bold = True
                  objExcel.Cells(4,1).Font.Size = 11
                  objExcel.Cells(4,2).Value = "Email Address"
                  objExcel.Cells(4,2).Font.Bold = True
                  objExcel.Cells(4,2).Font.Size = 11
                  objExcel.Cells(4,3).Value = "Creation Time"
                  objExcel.Cells(4,3).Font.Bold = True
                  objExcel.Cells(4,3).Font.Size = 11
                  
                  x = 5
                  y = 1
                  
                  For Each PFolder in colItems
                    strProxyAddresses = "IsMailEnabled= False"
                    strDisplayName = PFolder.AddressBookName
                    strSecondary = ""
                    Secondary = ""
                    If PFolder.IsMailEnabled=TRUE then
                      strProxyAddresses = GetProxies(strDisplayName)
                    End If
                  
                  y1 = y
                        objExcel.Cells(x,y1).Value = strDisplayName
                        y1 = y1 + 1
                        objExcel.Cells(x,y1).Value =  strProxyAddresses
                        y1 = y1 + 1
                        objExcel.Cells(x,y1).Value = PFolder.CreationTime
                        x = x + 1 'go to the next Row
                  
                  Next
                  
                  objExcel.Columns("A:C").Select
                  objExcel.Selection.HorizontalAlignment = 3 'xlCenter
                  objExcel.Selection.Borders.LineStyle = 1 '= xlSolid
                  
                  objExcel.Range("A1","C1").MergeCells = 1
                  objExcel.Range("A2","C2").MergeCells = 1
                  
                  objExcel.Columns("A:AH").EntireColumn.AutoFit
                  
                  objExcel.DisplayAlerts = False
                  Set objWorkbook = objExcel.ActiveWorkbook
                  objWorkbook.SaveAs strFile
                  objWorkbook.Close
                  objExcel.Quit
                  
                  msgbox "Script Complete!"
                  
                  Wscript.Quit
                  
                  Function GetProxies(AddressBookName)
                     on error resume next
                     Primary = ""
                     Secondary =  ""
                     Set rootDSE = GetObject("LDAP://RootDSE")
                     DomainContainer = rootDSE.Get("defaultNamingContext")
                  
                     Set conn = CreateObject("ADODB.Connection")
                     conn.Provider = "ADSDSOObject"
                     conn.Open "ADs Provider"
                  
                     ldapStr = "<LDAP://" & DomainContainer & ">;(&(&(&(&" &  _ 
                       "(| (objectCategory=publicFolder) )))(objectCategory=publicFolder)" & _
                       "(displayName="& AddressBookName &")));adspath;subtree"
                  
                     Set rs = conn.Execute(ldapStr)
                  
                     Set oPublicFolder = GetObject(rs.Fields(0).Value)
                  
                     err.Erase
                     For each email in oPublicFolder.proxyAddresses
                         If Left(email,5) = UCase("SMTP:") Then
                              Primary = Mid (email,6)
                              'Exit For
                         ElseIf Left(email,5) = LCase("smtp:") Then
                            Secondary =  Mid (email,6) & "; " & Secondary
                         End If
                     Next
                     If Err.number then _
                     Primary = Mid (oPublicFolder.proxyAddresses,6)
                  
                     GetProxies = Primary
                  
                  End Function

                  Comment


                  • #10
                    Re: Public Folder

                    I took this a little bit further...and was researching on how to find out what members or users have permissions to a specific public folder...I have been unable to find anything on that...

                    I think since we're already using LDAP saved queries thats looking at the email addresses, it should be able to see the objects that have permission on them too...but it's not really to the mailbox, its the public folder. I'm not sure if this is possible...

                    Comment


                    • #11
                      Re: Public Folder

                      I made little corrections to the script.

                      (I wrote err.Erase , that had to be: Err.Clear !)
                      Last edited by Rems; 27th June 2007, 23:50.

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment


                      • #12
                        Re: Public Folder

                        Oh...I didn't notice that lol. Well it still worked either way.

                        Comment


                        • #13
                          Re: Public Folder

                          Oh my god, you just saved me many hours of work!!!!!! We just went through an acquisition and consolidation, and one of the things i needed to do was get all of our email addresses, including Public Folders so we can setup new email addresses for the folders. This is exactly what i was looking for. One thing, is it possible to maybe get the full folder path in this export? We have many folders nested within folders, within folders, and i would love to be able to have the full path. It could either be in the folder name field, or in additional columns.

                          Any help (beyond what you have already provided) would be greatly appreciated.

                          Thanks much (and yes, i did boost your reputation points, you deserved it!!)

                          app

                          Comment


                          • #14
                            Re: Public Folder

                            I think you would use this...

                            Code:
                            PFolder.FolderTree
                            *Edit - They will probably be really long paths though and hard to read in the excel file, depending on how much you have the folders nested...
                            Last edited by ekrengel; 19th July 2007, 16:12.

                            Comment


                            • #15
                              Re: Public Folder

                              Hmmm, that just gives me
                              Code:
                              Exchange_FolderTree.Name="Public Folders",AdministrativeGroup="Evault Exchange"
                              Where could i look for what i am trying to locate?

                              thanks for the help

                              app

                              Comment

                              Working...
                              X