Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output constant text in Format-Table column 1

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
0
0
GB
Hallo,

I want to output the same text in every column in a format table, i.e.

Code:
Get-EventLog -LogName System -Newest 3 | Format-Table -Property @{Label="MyLabel";Expression="MyMsg"}, Message -Autosize

gives

Code:
MyLabel Message                                                                        
------- -------                                                                        
        The Multimedia Class Scheduler service entered the stopped state.              
        The WinHTTP Web Proxy Auto-Discovery Service service entered the stopped state.
        The Multimedia Class Scheduler service entered the running state.

but I want

Code:
MyLabel Message                                                                        
------- -------                                                                        
MyMsg   The Multimedia Class Scheduler service entered the stopped state.              
MyMsg   The WinHTTP Web Proxy Auto-Discovery Service service entered the stopped state.
MyMsg   The Multimedia Class Scheduler service entered the running state.

Any ideas? I've looked at FormatString but can't find a way to specifiy literal text, only "N3" etc.

TIA,

- Frink

 
The item for Expression has to be surrounded by braces, even if it's just a string. Your code should read:
Code:
@{Label="MyLabel";Expression={"MyMsg"}}
 
Brilliant. I was stuck on that one. Can you recommend a good resource for Powershell Syntax? The websites (except Tek-Tips, of cource) all seem to have the same noddy examples. It'd be handy to have a complete language reference, with examples, to complement the Get-Help stuff.

Thanks again,

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top