Announcement

Collapse
No announcement yet.

How to search for a particular value for profile path

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

  • How to search for a particular value for profile path

    Hello,

    I would like to search for all users in AD who have a specific profile path and then export them to an Excel Spreadsheet.

    I have already cobbled together (stolen) a script which will return all the profile directories of every user and write them to a spread sheet.

    Now I want to limit the scope to users with a particular server name in the path.

    I'd like to query for all users with a value containing \\specificserver and then export only those records to the spread sheet.

    This is the script I am using now:

    set objRootDSE = getobject("LDAP://RootDSE")
    strExportFile = "C:\temp\MyExport.xlsx"
    strRoot = objRootDSE.GET("DefaultNamingContext")
    strfilter = "(&(objectCategory=Person)(objectClass=User))"
    strAttributes = "sAMAccountName,profilepath,homedirectory"
    strScope = "subtree"
    SET cn = CREATEOBJECT("ADODB.Connection")
    SET cmd = CREATEOBJECT("ADODB.Command")
    cn.Provider = "ADsDSOObject"
    cn.Open "Active Directory Provider"
    cmd.ActiveConnection = cn
    cmd.Properties("Page Size") = 1000
    cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & _
    strAttributes & ";" & strScope
    SET rs = cmd.EXECUTE
    SET objExcel = CREATEOBJECT("Excel.Application")
    SET objWB = objExcel.Workbooks.Add
    SET objSheet = objWB.Worksheets(1)
    FOR i = 0 To rs.Fields.Count - 1
    objSheet.Cells(1, i + 1).Value = rs.Fields(i).Name
    objSheet.Cells(1, i + 1).Font.Bold = TRUE
    NEXT
    objSheet.Range("A2").CopyFromRecordset(rs)
    objWB.SaveAs(strExportFile)
    rs.close
    cn.close
    SET objSheet = NOTHING
    SET objWB = NOTHING
    objExcel.Quit()
    SET objExcel = NOTHING
    Wscript.echo "Script Finished..Please See " & strExportFile

    Thanks,

    John

  • #2
    Re: How to search for a particular value for profile path

    Ok then,

    Are there any other sites I can post my questions on?

    Comment


    • #3
      Re: How to search for a particular value for profile path

      Yes, I'm sure there are.

      Please be aware that people here give up their free time to help with questions, and have day jobs, families and even social lives.

      If you require a response in a particular timescale, please contact Microsoft Product Support Services, who will put a dedicated team onto it immediately. They accept all major credit cards.
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

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

      Comment


      • #4
        Re: How to search for a particular value for profile path

        I am well aware of the nature of forums.

        I posted 3 days ago, and got no response. I figured that was because no one who read my posts knew how to help me.

        I'm absolutely fine with that.

        I just figured that people on here would know of other resources that I might be able to use.

        So I asked.

        Nothing negative was implied or meant.

        It was a simple question and did not require a response of the nature of yours.

        And guess what? I know that Microsoft takes credit cards, but thanks for the tip anyway.

        And in the time it took you to come up with your snarky defensive answer you probably could have posted a link to other forums I could use.

        Comment


        • #5
          Re: How to search for a particular value for profile path

          I think Ossian gets this a lot Morgan300 so don't take it to heart. Sometimes it take a while to get an answer as we are all busy that's all (assuming we have any idea of course!)

          You could try adfind:
          http://www.joeware.net/freetools/

          adfind -csv -f "(profilepath=*servername*)" > c:\export.csv

          If you want additional properties add them in at the end ie:

          adfind -csv -f "(profilepath=*servername*)" samaccountname description > c:\export.csv
          cheers
          Andy

          Please read this before you post:


          Quis custodiet ipsos custodes?

          Comment

          Working...
          X