VMware Cloud Community
Troy_Clavell
Immortal
Immortal

VMware Tools Sync and W32Time

I have this code:

Get-VM | % { Get-View $_.ID} | `
% {
$spec = new-object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.syncTimeWithHost = $false
Get-View($_.ReconfigVM_Task($spec))
}
$Service = "W32Time"
$arrComputer = Get-Content("c:\pclist.txt")
foreach($strComputer in $arrComputer)
{

Get-Service W32Time
$time = get-wmiobject win32_service -ComputerName $strComputer | where-object {$_.Name -eq "W32Time"}
$time.ChangeStartMode("automatic")
$status = (Get-Service -Name $Service -ComputerName $strComputer)
                if($status.status -eq "stopped")
                {
                                ($status).start()
                }
}

...but I can't figure out how to make get the get-vm to only pull from the c:\pclist.txt file. Right now it walks every VM in vCenter to uncheck the sync option in the tools, and I don't want to go through 600 of them. Only ones in the text file.

Hope this makes sense.

0 Kudos
1 Reply
Troy_Clavell
Immortal
Immortal

got it


$Service = "W32Time"
$arrComputer = Get-Content("c:\pclist.txt")

foreach($strComputer in $arrComputer)
{
Get-VM -Name $strComputer | % { Get-View $_.ID} | `
% {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.syncTimeWithHost = $false
Get-View($_.ReconfigVM_Task($spec))
}

Get-Service W32Time
$time = Get-WmiObject win32_service -ComputerName $strComputer | where-object {$_.Name -eq "W32Time"}
$time.ChangeStartMode("automatic")
$status = (Get-Service -Name $Service -ComputerName $strComputer)
                if($status.status -eq "stopped")
                {
                                ($status).start()
                }
}

0 Kudos