# Pulling extensionAttributes and Department from AD

**URL:** <https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980>\
**Category:** PowerShell Help\
**Created:** [July 17, 2018, 2:19pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980 "2018-07-17T14:19:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![teddyb](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@teddyb](https://forums.powershell.org/u/teddyb)\
**Post date:** [July 17, 2018, 2:19pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/1 "2018-07-17T14:19:00Z")

</div>

Hey All,

New Powershell user here and I am looking for some insight. I have to pull the following items from Active Directory and dump them into a spreadsheet…

extensionAttribute1  
extensionAttribute2  
Department

Is it possible to pull this information using “objectGUID” ? I have over 2000 AD users/objects that I need to pull this info so we can import it into GCDS (Google Cloud). Any help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [July 17, 2018, 3:14pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/2 "2018-07-17T15:14:53Z")

</div>

You don’t say what you’ve tried or what issues you are having.

Or, do you mean this…

```
Get-ADUser -Identity $env:USERNAME -Properties * | Select ObjectGUID,extensionAttribute1,extensionAttribute2
```

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [July 18, 2018, 2:44pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/3 "2018-07-18T14:44:36Z")

</div>

In Powershell, most cmdlets will return default properties. You can see in the example below with Get-Service, only 3 properties are returned, the others hidden until we do Select -Properties \*:

```
PS C:\WINDOWS\system32> Get-Service | Select -First 1

Status Name DisplayName                           
------ ---- -----------                           
Stopped 010170153020298... McAfee Application Installer Cleanu...

PS C:\WINDOWS\system32> Get-Service | Select * -First 1

Name : 0101701530202980mcinstcleanup
RequiredServices : {}
CanPauseAndContinue : False
CanShutdown : False
CanStop : False
DisplayName : McAfee Application Installer Cleanup (0101701530202980)
DependentServices : {}
MachineName : .
ServiceName : 0101701530202980mcinstcleanup
ServicesDependedOn : {}
ServiceHandle : 
Status : Stopped
ServiceType : Win32OwnProcess
StartType : Automatic
Site : 
Container
```

For WMI and Active Directory, only certain properties are returned in the resultset, simply for speed. Returning 10 properties or 100 properties multiplied by the number of objects (like 1000 users) is going to return at much different performance levels. As postanote eluded, you need to tell the cmdlet that you want additional properties returned in the query. Using -Properties \* will return ALL properties. You can also specify just the properties you require to increase performance:

```
Get-ADUser -Identity $env:USERNAME -Properties ObjectGUID,extensionAttribute1,extensionAttribute2 | Select ObjectGUID,extensionAttribute1,extensionAttribute2
```

---

<div class="post-metadata">

**Author:** ![teddyb](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@teddyb](https://forums.powershell.org/u/teddyb)\
**Post date:** [July 19, 2018, 9:57am UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/4 "2018-07-19T09:57:33Z")

</div>

This is basically what I’ve been using so far…

$objectlist = Import-Csv .\objects.csv

foreach ($obj in $objectlist) {  
$aduser = Get-ADUser “$($obj.ObjectGUID)” -Properties department, extensionAttribute1, extensionAttribute2, ObjectGUID  
Write “Dept is $($aduser.department) extAtt1 is ‘$($aduser.extensionAttribute1)’ extAtt2 is ‘$($aduser.extensionAttribute2)’”  
}

The Write command is in there purely for testing to make sure that it’s returning values (which it is). Now I just need to export that data to a csv. Granted I have only tested this against users, not contacts or groups yet. I appreciate the input.

---

<div class="post-metadata">

**Author:** ![skalizar](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@skalizar](https://forums.powershell.org/u/skalizar)\
**Post date:** [July 23, 2018, 12:07pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/5 "2018-07-23T12:07:36Z")

</div>

You have the basics. Just need the export. (Untested from memory only)

```
$aduser = @()
foreach ($obj in $objectlist) {
  $aduser += Get-ADUser "$($obj.ObjectGUID)" -Properties department, extensionAttribute1, extensionAttribute2, ObjectGUID
}
$aduser | Select-Object ObjectGUID,department,extensionAttribute1,extensionAttribute2 | Export-Csv 'C:\path\file.csv' -NoTypeInformation
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/pulling-extensionattributes-and-department-from-ad/10980/6 "2024-05-16T20:34:39Z")

</div>


