how I can execute below command in list of servers

Welcome Forums General PowerShell Q&A how I can execute below command in list of servers

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #63827

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member
    (Get-Help Invoke-Command -Examples).examples.example[6]
    
  • #63836

    Participant
    Points: 0
    Rank: Member
    $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

    Participant
    Points: 0
    Rank: Member

    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

    • #63845

      Participant
      Points: 0
      Rank: Member

      Thank You it worked..

The topic ‘how I can execute below command in list of servers’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort