Powershell active directory properties

房东的猫 提交于 2020-01-05 05:57:34

问题


I am trying to find the properties of active directory:

$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"

$colResults = $objSearcher.FindAll() 

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

I can call $objitem.name, but I don't know which other properties I have accessible.

How can I find which properties I can access from $objitem?

edit:

Used this solution using the answers below:

foreach ($objResult in $colResults){   
   ($colResults)[0].Properties.PropertyNames
}

回答1:


foreach ($objResult in $colResults){   
    $objResult.Properties | % {$_.propertynames}
}

should display the keys of each result property.




回答2:


Use the get-member (aliased as gm) cmdlet to get all the properties and methods. Like so,

$objItem | gm

Another a way is to pipe the object to format-list (aliased as fl) cmdlet, which won't list methods. Like so,

$objItem | fl *




回答3:


Ok, preceding answers are "Powershell" features. If you really want to know what are the attributes you can reach for a given class (clas user here) you have to have a look to the Schema. which is avaible on Windows server registering the schmmgmt.dll COM object.

C:\>regsvr32 c:\WINDOWS\system32\schmmgmt.dll

JP



来源:https://stackoverflow.com/questions/5594334/powershell-active-directory-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!