VMware Cloud Community
Cicciuzz
Contributor
Contributor

Again Date Format Problem

Hello everybody,

I made this script to collect stats for the vms.

I need to load data in mysql, but the date is a problem.

The date I get is related to the culture, but as you well know, MySql wants the Uformat for the time stamp.

$vCenter = "" ###

$VMList = ".txt" ###

$sdate = Get-Date 01/01/2018 ###

$fdate = Get-Date 01/04/2018 ###

$ExportPath = ".csv" ###

$VMs = Get-Content $VMList

$Lines = type $VMList | Measure-Object -Line

$TotalObjects = $Lines.Lines

$stats = @()

Import-Module -Name VMware.VimAutomation.Core

Connect-VIServer -Server $vCenter -Protocol https -User  -Password

$counter=1

foreach($VM in $VMs)

    {

     Write-Host -NoNewline "Collecting data for" $VM "..."

     $stats += Get-Stat -Entity $VM -Start $sdate -Finish $fdate -Stat cpu.usage.average, mem.usage.average

     Write-Host " ( Done." $counter "out of" $TotalObjects ")" -ForegroundColor Yellow

     $counter=$counter+1

    }

$stats | Export-Csv -Path $ExportPath -Force -NoTypeInformation

Disconnect-VIServer $vCenter -Confirm:$false

Write-Host "Disconneted from " $vCenter

0 Kudos
1 Reply
LucD
Leadership
Leadership

Have a look at Re: Convert Get-Date into Unix EPOCH Format


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos