开发者

Wrong time format returned by get-counter/export-counter in Powershell

The get-counter/export-counter cmdlets in powershell seem to return dates in the U开发者_开发技巧S format which is rather undesirable in this case. I went through both get-help -full pages and couldn't find anything that allows me to set the date/time format. Is there another way to do this that I am not aware of, or am I stuck with the US date format?


It works so because the culture of your host is "en-US" have a look to :

Get-Culture | Format-List *

You can change the culture during a Scriptblock execution look at this code

[System.Globalization.CultureInfo] $culture = "en-US"
$a = { [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
       [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
       get-counter -Counter "\Processeur(_Total)\% temps processeur" -SampleInterval 2 -MaxSamples 3
     }
&$a

[System.Globalization.CultureInfo] $culture = "fr-FR"
$a = { [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
       [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
       get-counter -Counter "\Processeur(_Total)\% temps processeur" -SampleInterval 2 -MaxSamples 3
     }

&$a

There are a lots of information about that in Powershell-cookbook


You can always re-format the output:

get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 3 | 
select @{l="Timestamp";e={([datetime]"$($_.timestamp)").tostring("yyyy/MM/dd HH:mm:ss")}},Readings | fl





Timestamp : 2011/06/21 18:33:09
Readings  : \\TMA-1\processor(_total)\% processor time :
            3.87658516403437



Timestamp : 2011/06/21 18:33:11
Readings  : \\TMA-1\processor(_total)\% processor time :
            1.93861060616496



Timestamp : 2011/06/21 18:33:13
Readings  : \\TMA-1\processor(_total)\% processor time :
            3.10139633471207
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜