0

newb here with my first question.

I'm trying to do an AD query using powershell which works but I want to change the column headings. I've tried searching and have found some examples but I can't get them to seem to work.

Here is my code so far:

Get-ADUser -Filter * -Properties 
Description,extensionAttribute14,PasswordLastSet,EmailAddress |Sort-Object 
Description,PasswordLastSet,SamAccountName| Where-Object {$_.SamAccountName -like 
"*abcd.*"} | ft -Autosize 
Description,PasswordLastSet,SamAccountName,Name,extensionAttribute14,EmailAddress

Whilst this produces the data I want I want to rename the column heading for "extensionAttribute14" to something "Contact Number" because I want to produce this out regularly and send it to the help desk.

I've also tried code similar to below but although that changes the column names to what I want it "bunches up" the output rather than giving me one line per user account.

$UserDetails = Get-ADUser -Filter * -Properties 
Description,extensionAttribute14,PasswordLastSet,EmailAddress | Where-Object 
{$_.SamAccountName -like "*abcd12.*" } 
$UserOutput = New-Object psobject -Property @{
    Username = $UserDetails.SamAccountName
    Mobile = $UserDetails.extensionAttribute14
    }
$UserOutput | ft -Autosize UserName,Mobile

Any suggestions on how to complete my goal gratefully received.

  • The code has a few extra linebreaks that create syntax errors. But $userDetails is an array so has to be piped to something like foreach-object. 'samaccountname -like "\*abcd12.\*" can also be in the -filter for get-aduser for more efficiency. – js2010 Sep 22 '22 at 16:16
  • Use a [calculated property](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Calculated_Properties); see the linked duplicate for details. – mklement0 Sep 22 '22 at 17:01

0 Answers0