Author Posts

February 9, 2017 at 11:50 am

how I can execute below command in list of servers

w32tm /config /syncfromflags:domhier /reliable:no; w32tm /config /update; net stop w32time; net start w32time; w32tm /resync /rediscover

February 9, 2017 at 12:15 pm

(Get-Help Invoke-Command -Examples).examples.example[6]

February 9, 2017 at 12:16 pm

$ServerListFile = "C:\w32\servers.txt"  
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue 
$Result = @()

Foreach($ServerName in $ServerList)

{
w32tm /config /syncfromflags:domhier /reliable:no; w32tm /config /update; net stop w32time; net start w32time; w32tm /resync /rediscover

}

created like above , I need to get output in csv with server name and sync status.. can you help me to update further the script

February 9, 2017 at 12:28 pm

your cycle does not run on these servers. it runs locally
if you plan to use Invoke-Command you should change it to

Invoke-Command -ComputerName $ServerList {
#[...]
  $output = w32tm /resync /rediscover
  [PSCustomObject]@{
    ComputerName = $Env:ComputerName
    Status = $output #may be it need to be parsed here
  }
} | Export-Csv -NoTypeInformation -Path c:\data.csv

or add to w32tm calls /computername parameter and change service work to native powershell stop-service/start-service

February 9, 2017 at 12:40 pm

Thank You it worked..