how I can execute below command in list of servers

This topic contains 4 replies, has 2 voices, and was last updated by  Keshav Prasad 8 months, 1 week ago.

  • Author
    Posts
  • #63827

    Keshav Prasad
    Participant

    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
  • #63833

    Max Kozlov
    Participant
    (Get-Help Invoke-Command -Examples).examples.example[6]
    
  • #63836

    Keshav Prasad
    Participant
    $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

  • #63841

    Max Kozlov
    Participant

    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

You must be logged in to reply to this topic.