gpt4 book ai didi

powershell 获取 aduser 扩展属性12

转载 作者:行者123 更新时间:2023-12-01 19:40:56 28 4
gpt4 key购买 nike

$name="d4rkcell"
Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12

我正在使用上面的代码,但结果显示的不仅仅是extensionAttribute12,它还显示其他信息,例如:

DistinguishedName    : CN=d4rkcell,OU=Users,...DC=co,DC=uk
Enabled : True
extensionAttribute12 : \\path\to\a\share
GivenName : Joe
Name : U0023883
ObjectClass : user
ObjectGUID : a0562e97-cb58-463b-bae6-8e0087fa494b
SamAccountName : d4rkcell
SID : S-1-5-21-1004336368-1374586140-1801574631-62475
Surname : Bloggs
UserPrincipalName : J.Bloggs@....co.uk

理想情况下,我只想将值存储在extensionAttribute12中,任何人都可以在这里帮助我或帮助我分割这个字符串吗?有点卡住了,非常感谢帮助。

最佳答案

Get-ADUser-Properties 参数似乎有点误导。据其documentation :

Properties

Specifies the properties of the output object to retrieve from the server. Use this parameter to retrieve properties that are not included in the default set.

因此,除了默认设置之外,您指定的任何属性似乎都会被返回。如果您想进一步将某个属性与该集合隔离,您可以尝试:

$name="d4rkcell"
Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12 |
Select-Object -ExpandProperty extensionAttribute12

如果您始终希望获得包含属性的单个对象,则可以通过将 Get-ADUser 命令括在括号中,然后在属性名称后附加一个点来缩短此过程:

(Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12).extensionAttribute12

关于powershell 获取 aduser 扩展属性12,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637025/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com