Hi,
I have this ps, that I used to collect information about ESX servers, and I need to insert this information in a MySQL DB.
The timestamp came with this format "14/02/2014 10:00:00" and I need to change it ti 2014-02-14 10:0:0. I have test with -Useculture, format and ToString method also change regional setting without success
Any ideas will be appreciate
The original code
////////
$IntervalFinish = Get-Date
$IntervalStart = $IntervalFinish.addDays(-30)
$esx = Get-VMHost |Where-object {$_.powerstate -eq "poweredon"}
Get-Stat -entity $esx -stat cpu.usage.average, mem.usage.average -Start $IntervalStart -Finish $IntervalFinish -IntervalMins 120 | where{$_.instance -eq ""} | Export-Csv temp_monthl.csv -NoTypeInformation -UseCulture
////////////////////////
SALUD....
Try like this
$IntervalFinish = Get-Date
$IntervalStart = $IntervalFinish.addDays(-30)
$esx = Get-VMHost |Where-object {$_.powerstate -eq "poweredon"}
Get-Stat -Entity $esx -Stat cpu.usage.average, mem.usage.average -Start $IntervalStart -Finish $IntervalFinish -IntervalMins 120 |
where{$_.instance -eq ""} |
Select -ExcludeProperty Timestamp -Property *,@{N="TimeStamp";E={$_.Timestamp.ToString("yyyy-MM-dd hh:%m:%s")}} |
Export-Csv temp_monthl.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This has the get-date formatting info
Windows PowerShell Tip: Formatting Dates and Times
I assume you want the TimeStamp property in that specific format ?
Then you could do something like this
Get-Stat -Realtime -Stat cpu.usage.average -Entity $esx -MaxSamples 1 |
Select @{N="TimeStamp";E={$_.Timestamp.ToString("yyyy-MM-dd hh:%m:%s")}}
Don't mind the Get-Stat part, it's the calculated property
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Atleast I got a couple responses in before The Wizard LucD returned ![]()
Wow, works.
Obviuosly only TimeStamp is exported, How can I integrate with my own code?
Have I to include in the SELECT the name of the objets that I want to export?
SALUD
Try like this
$IntervalFinish = Get-Date
$IntervalStart = $IntervalFinish.addDays(-30)
$esx = Get-VMHost |Where-object {$_.powerstate -eq "poweredon"}
Get-Stat -Entity $esx -Stat cpu.usage.average, mem.usage.average -Start $IntervalStart -Finish $IntervalFinish -IntervalMins 120 |
where{$_.instance -eq ""} |
Select -ExcludeProperty Timestamp -Property *,@{N="TimeStamp";E={$_.Timestamp.ToString("yyyy-MM-dd hh:%m:%s")}} |
Export-Csv temp_monthl.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
