none
Script not retreiving certain attributes RRS feed

  • Question

  • Hi,

    I would have thought the following script would write out the following attributes to a csv file file but it's not

    name, mail, userprincipalname

    $strFilter = "(objectCategory=User)"

    $objDomain = New-Object System.DirectoryServices.DirectoryEntry

    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
    $objSearcher.SearchRoot = $objDomain
    $objSearcher.PageSize = 1000
    $objSearcher.Filter = $strFilter
    $objSearcher.SearchScope = "Subtree"

    $colProplist = "name", "mail", "userPrincipalName"
    foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i) > $Null}

    $colResults = $objSearcher.FindAll()

    foreach ($objResult in $colResults)
        {$objItem = $objResult.Properties; $objItem.name}

     

    Its only showing the name field and leaving out the other two. Could anybody please tell me what needs to be changed to have all three attributes added to the csv file please

    Tuesday, October 25, 2011 1:33 PM

Answers

  • Your script only outputs the one value. Assuming what you have works, I would suggest code similar to below for the ForEach:

     

    foreach ($objResult in $colResults)
    {
        $objItem = $objResult.Properties
        $objItem.name + "," + $objItem.mail + "," + $objItem.userPrincipalName
    }

    -----

     

    As with most administrative scripts, this one is designed to have the output redirected to a text file (in this case with values comma delimited).

     


    Richard Mueller - MVP Directory Services
    Tuesday, October 25, 2011 2:06 PM
    Moderator

All replies