Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

OK. I'm just drawing a blank here or I'm missing something obvious. In a Powershell (V3) script, I'm calling

Get-ADUser -Filter 'SAMAccoutnName -like $ADUserName' -Properties Name,SamAccountName,EmailAddress | Select-Object Name, SamAccountName, EmailAddress

It lists the data in the column format I would expect

Name           SamAccountName          EmailAddress
------         ---------------         ------------
User Name      username                user.name@co.com

That's not the problem. When I call a different command after that in the script (Exchange 2013 actually)

Get-Mailbox -Identity username | Select-Object Name, SAMAccountName, PrimarySMTPAddress

I only get the corresponding columns from the earlier Select-Object with no headers:

User Name     username

Even if I specifically ask for a different set such as that "PrimarySMTPAddress" from above.

What am I missing here? This is driving me crazy.

Thanks in advance.

share|improve this question
2  
I don't have the Exchange Cmdlets right here in front of me right now, but uh, what properties does Get-Mailbox -Identity username | select * actually return? Does the return object actually contain the properties that you're trying to select? –  Ryan Ries Sep 19 '13 at 1:16
    
That returns quite a bit of properties but I've been able to run that above command and return those properties from a shell by itself, it's just that in the script it seems to only want to continue to use that fist Select-Object table that I used with the Get-ADUser ahead of it in the same script. While in the shell I can run them both manually and I get what I would expect, two different Select-Object sets with two headers for two tables. There has got to be something in the way PowerShell runs a script that changes that behavior, but I can't find it anywhere. –  Jason Sep 19 '13 at 13:22
1  
Can you show us the entire script/function? –  Mathias R. Jessen Sep 22 '13 at 21:30

1 Answer 1

The problem here is the fact that if you run select-object as a last cmdlet in pipeline with different set of properties, PowerShell will not "implicitly" call Out-Default for each command, so it won't "reset" formatting.

But what is not done implicitly, can always be done explicitly. Just output any command (maybe except last one) to Out-Default:

ls | select Name | Out-Default
ls | select DirectoryName
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.