I have a powershell script that queries vCenter for the location of virtual machines but I have been unable to get the timestamp produced by Get-Date to be used as Time by Splunk.
Here is my script:
Connect-VIServer -Server server_name -user user_name -Password password
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
(get-date).ToString("yyyy-MM-dd HH:mm:ss") + " VM_Guest=""" + $VM.Name + """, VM_Datacenter=""" + $Datacenter.name + """, VM_Cluster=""" + $Cluster.Name + """, VM_Host=""" + $vm.VMHost.Name + """"
}
}
}
$VmInfo | Add-member -MemberType AliasProperty -Name SPLUNKTIME -value (get-date).ToString("yyyy-MM-dd HH:mm:ss") -PassThru
$VmInfo | Get-Member SPLUNKTIME | Write-Output
Disconnect-VIServer -server sw-vcenterpr71 -Confirm:$False
... View more