locked
Monitoring NTP Source. RRS feed

  • Question

  • Hi,

    I'm doing a PowerShell script to monitoring NTP configurations. I get my local source through w32tm command and compare with another source wich I passed as a parameter. My problem is when my script it. I don't know why these strings comparison doesn't work.

    Below my simple code.

    param([string]$arg0)
    $ntp_default= $arg0
    $ntp_local = w32tm /query /source
    $ntp_compare= [string]$ntp_default -eq [string]$ntp_local
    echo $ntp_compare
    echo $ntp_default
    echo $ntp_local

    Same strings always return 'false'.

    Thank you!




    Tuesday, June 20, 2017 2:36 PM

Answers

  • Try this:

    $ntp_default.Trim() -eq $ntp_local.Trim()


    \_(ツ)_/

    • Marked as answer by Gui Santos' Tuesday, June 20, 2017 7:26 PM
    Tuesday, June 20, 2017 2:54 PM

All replies

  • Please fix your post - it is unreadable.


    \_(ツ)_/

    Tuesday, June 20, 2017 2:43 PM
  • I'm so sorry! I fixed my text.
    Tuesday, June 20, 2017 2:48 PM
  • They won't compare if the strings are no absolutely identical.

    Without an example it will not be possible to know what you are seeing.

    w32tm returns this kind of string: "time.nist.gov,0x1"

    Notice the 0x1 which may not be returned from other utilities.


    \_(ツ)_/

    Tuesday, June 20, 2017 2:51 PM
  • Try this:

    $ntp_default.Trim() -eq $ntp_local.Trim()


    \_(ツ)_/

    • Marked as answer by Gui Santos' Tuesday, June 20, 2017 7:26 PM
    Tuesday, June 20, 2017 2:54 PM
  • It's works

    Thank You jrv!!!
    Tuesday, June 20, 2017 7:27 PM