1

When I run Get-Recipient | ft Name in the console everything looks good, but when I try it in a script the output is just a list of class names; Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
How do I fix this? Thankful for any and all help!

//David

1 Answer 1

5

The Format-* cmdlets should only be used to control display of data. They should rarely if ever be used inside "library" type scripts or functions, expect maybe when displaying status messages or something. The actual output of a Format-* cmdlet is a bunch of magic objects (the FormatEntryData guys) that direct the Powershell engine on how to do display formatting.

It works in the console because you are not capturing your data, you are just letting it display to the screen.

In your script, you should just return the data as-is, and let the caller decide how to format it, if (s)he wants to. If you want to return back only the Name field, use Select-Object Name to pare away the other fields.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.