rated by 0 users
This post has 2 Replies | 1 Follower

Not Ranked
Posts 2
Dan Posted: 05-11-2012 2:53 PM

I've written a script that builds an array containing information about server objects in my AD.  The script seems to be doing what I want, but the resulting objects have all their data enclosed in braces.  I've tried using tostring() to convert them, but then the data just disappears.  Cany anyone point out where I'm going wrong and/or what I need to do to fix it?




$Servers = @()

$ADServers = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc=myDomain,dc=ca")
$ADSearcher = New-Object System.DirectoryServices.DirectorySearcher($ADServers)
$ADSearcher.SearchScope = "Subtree"
$ADSearcher.Filter = ("(&(objectCategory=Computer)(operatingsystem=*Server*))")
$SearchResult = $ADSearcher.FindAll()

foreach ($Result in $SearchResult){
 $Server = $Result.Properties
    $CurrentServerObject = New-Object –TypeName PSObject –Property (@{
        operatingsystemversion = $server.operatingsystemversion
        lastlogontimestamp = $server.lastlogontimestamp
        objectsid = $server.objectsid
        whencreated = $server.whencreated
        name = $
        dnshostname = $server.dnshostname
        samaccounttype = $server.samaccounttype
        distinguishedname = $server.distinguishedname
        cn = $
        objectcategory = $server.objectcategory
        serviceprincipalname = $server.serviceprincipalname
        objectclass = $server.objectclass
        objectguid = $server.objectguid
        operatingsystemservicepack = $server.operatingsystemservicepack
        samaccountname = $server.samaccountname
        whenchanged = $server.whenchanged
        operatingsystem = $server.operatingsystem
        adspath = $server.adspath
write-output $Servers   


Top 25 Contributor
Posts 296
Microsoft MVP
Top Contributor

Thats a limitation of the searcher class.

There is an example here

that shows how to get to the data without the {}

Not Ranked
Posts 2

Thanks for the link.  Unfortunately I'm getting an error related to the "AD" drive ("Get-ChildItem : Cannot find drive. A drive with the name 'Ad' does not exist.").  Is this drive related to some module I'm not loading, or a particular host OS?

I will continue to investigate this direction, however.  If my issue has to do with the searcher object itself, looking for a different path to the same data may still provide the answer.

Thanks again,



Page 1 of 1 (3 items) | RSS
Copyright 2012 All rights reserved.