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
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
(Get-Help Invoke-Command -Examples).examples.example[6]
$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
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
Thank You it worked…