是否可以在不使用Get-ADUser的情况下获取当前用户的AD属性? 我是 powershell 新手。我需要获取用户的一些属性,例如标题、电子邮件和部门。 我尝试使用:
get-wmiobject -Class win32_useraccount -Filter "name='John.Doe'" | select *
PSComputerName : NY-Z343
Status : OK
Caption : BEAZL-INC\john.doe
PasswordExpires : False
__GENUS : 2
__CLASS : Win32_UserAccount
__SUPERCLASS : Win32_Account
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
__PROPERTY_COUNT : 16
__DERIVATION : {Win32_Account, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : NY-Z343
__NAMESPACE : rootcimv2
__PATH : \BEAZL-INCrootcimv2:Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
AccountType : 512
Description : Dude account for gaming
Disabled : False
Domain : BEAZL-INC
FullName : John Doe
InstallDate :
LocalAccount : False
Lockout : False
Name : john.doe
PasswordChangeable : True
PasswordRequired : False
SID : S-1-5-21-3384058-193304-10174538-501
SIDType : 1
Scope : System.Management.ManagementScope
Path : \\NY-Z343\root\clmv2:Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
Options : System.Management.ObjectGetOptions
ClassPath : \\NY-Z34\root\clmv2:Win32_UserAccount
Properties : {AccountType, Caption, Description, Disabled...}
SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers : {dynamic, Locale, provider, UUID}
Site :
Container :
是的,您可以使用
[adsisearcher]
,它是 .NET 的 DirectorySearcher
类的类型加速器。这不需要安装任何额外的东西。
以下示例将通过
name
属性搜索用户并返回 title
、mail
和 department
属性:
# This is the search filter
$searcher = [adsisearcher]"(&(objectClass=user)(objectCategory=person)(name=John.Doe))"
# List all the propterties you want to use
$searcher.PropertiesToLoad.AddRange(@("title", "mail", "department"))
# By default, it will search the same domain as the logged in user.
# If you need to search a different domain, uncomment and edit this line.
# $searcher.SearchRoot = [adsi]"LDAP://example.com"
$user = $searcher.FindOne()
$title = $user.Properties["title"][0]
当我使用时:
$Searcher=([adsisearcher]“对象类别=计算机”) $Searcher.Findone().Properties
如何使用 adsisearcher 获取所有属性? 我只获得了部分属性。 (约35) 如果我运行 get-adcomputer,我会获得更多的属性。 (约90)。也许其中一些是构造,但我如何判断是否获得了所有属性?