25

I want to write the output from a Format-List command to the event log so I need it as a string.

Is there a generic way to do this that doesn't depend on knowing what is being formatted?

1 Answer 1

37

Use the Out-String cmdlet:

... | Format-List | Out-String
Sign up to request clarification or add additional context in comments.

1 Comment

Ah. Just when I'm railing about how complicated everything is in PowerShell, it's not. Thanks very much.

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.