Changing column headings from powershell Query

Viewed 16

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.

0 Answers
Related