Having an issue figuring out a ps script to just read vm names from a csv and grab the timesync settings. Anybody have one laying around I might be able to get?
Here is the working I have so far...
# Define the path to your CSV file
$csvPath = "C:\Path\to\import.csv"
# Connect to the vCenter server
$vCenterServer = "server.name.com"
Connect-VIServer -Server $vCenterServer
# Import VM names from the CSV file
$vmList = Import-Csv -Path $csvPath
# Initialize an array to hold the results
$results = @()
foreach ($vm in $vmList) {
$vmName = $vm.VMName
try {
# Get the VM object
$vmObject = Get-VM -Name $vmName
# Get the VM Tools object
$vmTools = $vmObject.ExtensionData
# Check if VMware Tools is installed
if ($vmTools.Config.Tools -gt 0) {
# Retrieve the time sync settings from VMware Tools
$toolsTimeSyncEnabled = $vmTools.Config.Tools.SyncTimeWithHost
$results += [PSCustomObject]@{
VMName = $vmName
ToolsVersion = $vmTools.Config.Tools
TimeSyncEnabled = $toolsTimeSyncEnabled
}
} else {
$results += [PSCustomObject]@{
VMName = $vmName
ToolsVersion = "Not Installed"
TimeSyncEnabled = "N/A"
}
}
} catch {
Write-Warning "Failed to process VM: $vmName. Error: $_"
$results += [PSCustomObject]@{
VMName = $vmName
ToolsVersion = "Error"
TimeSyncEnabled = "Error"
}
}
}
# Export results to a CSV file
$outputPath = "C:\path\to\export\vm_tools_time_sync_settings.csv"
$results | Export-Csv -Path $outputPath -NoTypeInformation
# Disconnect from the vCenter server
Disconnect-VIServer -Server $vCenterServer -Confirm:$false
Write-Host "Time sync settings check complete. Results saved to $outputPath"