Reputation: 147
$name="d4rkcell"
Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12
I am using the above code but the result shows more than just extensionAttribute12 it shows other information such as:
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 : [email protected]
I would ideally just want the value stored in extensionAttribute12, can anyone help me here or help me split this string ? Bit stuck, help would be much appreciated.
Upvotes: 4
Views: 12459
Reputation: 1702
This showed up when I googled how to show all attributes, so I'll add this here. Note that's it's not very efficient, but I couldn't get a 1-15 loop to work.
get-aduser john -Properties * | select extensionattribute*
Upvotes: 0
Reputation: 26023
The -Properties
parameter of Get-ADUser
seems a little misleading. According to its 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.
So it seems any properties you specify will be returned in addition to the default set. If you want to further isolate a property from that set, you could try:
$name="d4rkcell"
Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12 |
Select-Object -ExpandProperty extensionAttribute12
If you always expect to get a single object containing properties, you could shorten this by wrapping the Get-ADUser command in parenthesis, and then appending the property name with a dot:
(Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12).extensionAttribute12
Upvotes: 2
Reputation: 3419
You should just be able to select extensionAttribute12, for example:
Get-ADUser -LDAPFilter "(sAMAccountName=$Name)" -Properties extensionAttribute12 | Select extensionAttribute12
Upvotes: 0