Solved

Powershell Format-List problem

Posted on 2007-11-20
3
1,053 Views
Last Modified: 2012-06-27
Hi,

I am running the following powershell command:


get-alert | where {$_.ResolutionState -eq 0 } | Format-List MonitoringObjectDisplayName,Name,ResolutionState,RepeatCount,TimeRaised


Which displays the following:

MonitoringObjectDisplayName : SQL1
Name                        : The SQL Server Service Broker or Database Mirroring
                               transport is disabled or not configured
ResolutionState             : 0
RepeatCount                 : 1
TimeRaised                  : 20/11/2007 6:41:23 PM

The problem is the TimeRaised field is no in LocalTime, it is GMT time I suspect. I want to convert it
to my local time. (In my case GMT+10) if I try the following it does not work

get-alert | where {$_.ResolutionState -eq 0 } | Format-List MonitoringObjectDisplayName,Name,ResolutionState,RepeatCount,TimeRaised.ToLocalTime()


MonitoringObjectDisplayName : SQL1
Name                        : The SQL Server Service Broker or Database Mirroring
                               transport is disabled or not configured
ResolutionState             : 0
RepeatCount                 : 1

** No TimeRaised field **

Any suggestions on the syntax to make this work?

Thanks,

Ward
0
Comment
Question by:whorsfall
  • 3
3 Comments
 
LVL 18

Accepted Solution

by:
BSonPosh earned 500 total points
ID: 20322860
You can use calculated fields for Format-List

Format-List MonitoringObjectDisplayName,Name,ResolutionState,RepeatCount,@{l="TimeRaised";E={$_.TimeRaised.ToLocalTime()}}
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 20322904
FYI: For more info on Calculated Properties look at help for format-table (it works the same.)
PS> get-help format-table -full
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 20322957
I just saw your post on NG :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now