W32TM output assistance

This topic contains 1 reply, has 2 voices, and was last updated by  postanote 1 week, 3 days ago.

  • Author
    Posts
  • #81890

    Craig Rigden
    Participant

    I have been tasked with getting the Time Source, Precision and Last Successful Sync Time from multiple servers and then outputting them to a csv file so we can filter the results

    So far I have tried to get this information from my local machine but have fallen at the first hurdle.

    I can get the information from w32tm /query /computer:localhost /status but I can't work out how to extract the individual bits of information and then export it to a csv so they are in columns for filtering.

    Apologies for the lack of code however I am very new to this but have been tasked with this with little support.

  • #81970

    postanote
    Participant

    Well, PowerShell is Object based, but you can do lots of things with strings.
    The command you are using is a string adn hard to just do string maniplulation
    on it.

    Though not exactly what you are trying to do here, but...
    Folks have alerady done wotk to help here. For example, see...
    'jeffwouters.nl/index.php/2013/09/powershell-function-to-get-time-server-ntp-settings-from-clients'
    'gallery.technet.microsoft.com/scriptcenter/Check-timesource-W32TM-of-3d80b441/view/Discussions'

    All that being said, you can just extract the parts you need.

    # Use the localhost computer list to simple parse Win32tm output

    'localhost',$env:COMPUTERNAME `
    | % { w32tm /query /computer:$env:COMPUTERNAME /status }

    # Results

    Leap Indicator: 0(no warning)
    Stratum: 1 (primary reference – syncd by radio clock)
    Precision: -6 (15.625ms per tick)
    Root Delay: 0.0000000s
    Root Dispersion: 10.0000000s
    ReferenceId: 0x4C4F434C (source name: "LOCL")
    Last Successful Sync Time: 10/11/2017 11:12:47 PM
    Source: Free-running System Clock
    Poll Interval: 6 (64s)

    Leap Indicator: 0(no warning)
    Stratum: 1 (primary reference – syncd by radio clock)
    Precision: -6 (15.625ms per tick)
    Root Delay: 0.0000000s
    Root Dispersion: 10.0000000s
    ReferenceId: 0x4C4F434C (source name: "LOCL")
    Last Successful Sync Time: 10/11/2017 11:12:47 PM
    Source: Free-running System Clock
    Poll Interval: 6 (64s)

    # Parsing the host Win32tm output, the localhost computer list to simple parse Win32tm output
    Function Get-HostWin32tmConfiguration
    {
    [CmdletBinding()]
    Param
    (
    [string[]]$ComputerList = $env:COMPUTERNAME
    )

    ForEach ($TargetHost in $ComputerList)
    {
    (w32tm /query /computer:$TargetHost /status) -replace ': ',',' `
    | ConvertFrom-Csv -Header Name,Value `
    | Where {$_.Name -match "Source|Precision|Sync "} `
    | Select @{Name = 'HostName';Expression = {$TargetHost}},Name,Value
    }

    }

    # Write the CSV capture of the full request
    Get-HostWin32tmConfiguration -ComputerList ('localhost',$env:COMPUTERNAME) `
    | Format-Table -AutoSize

    # Results

    HostName Name Value
    ——– —- —–
    localhost Precision -6 (15.625ms per tick)
    localhost Last Successful Sync Time 10/11/2017 11:12:47 PM
    localhost Source Free-running System Clock
    WC01 Precision -6 (15.625ms per tick)
    WC01 Last Successful Sync Time 10/11/2017 11:12:47 PM
    WC01 Source Free-running System Clock

    # Or, just in case you wanted to pick more properties

    Function Get-HostWin32tmConfiguration
    {
    [CmdletBinding()]
    Param
    (
    [string[]]$ComputerList = $env:COMPUTERNAME
    )

    ForEach ($TargetHost in $ComputerList)
    {
    (w32tm /query /computer:$TargetHost /status) -replace ': ',',' `
    | ConvertFrom-Csv -Header Name,Value `
    | Select @{Name = 'HostName';Expression = {$TargetHost}},Name,Value
    }

    }

    # Write the CSV capture of the full request
    Get-HostWin32tmConfiguration -ComputerList ('localhost',$env:COMPUTERNAME) `
    | Select HostName,Name,Value `
    | Where Name -match 'Source|Precision|Sync' `
    | Format-Table -AutoSize

    HostName Name Value
    ——– —- —–
    localhost Precision -6 (15.625ms per tick)
    localhost Last Successful Sync Time 10/11/2017 11:12:47 PM
    localhost Source Free-running System Clock
    WC01 Precision -6 (15.625ms per tick)
    WC01 Last Successful Sync Time 10/11/2017 11:12:47 PM
    WC01 Source Free-running System Clock

You must be logged in to reply to this topic.