Просмотр источника времени

param($computer="localhost", $help)

function funline ([ref]$strIN)
{ 
 $num = $strIN.value.length
 for($i=1 ; $i -le $num ; $i++)
  { $funline += "=" }
    $strIN.value = "$($strIN.value)`n" + $funline
}

function funHelp()
{
$helpText=@"
DESCRIPTION:
NAME: GetTimeSource.ps1 
Prints the current time source on a local or remote machine.

PARAMETERS: 
-computer Specifies the name of the computer upon which to run the script
-help         prints help file

SYNTAX:
GetTimeSource.ps1 -computer MunichServer

Lists current time source on a computer named MunichServer

GetTimeSource.ps1 

Lists current time source on local computer

GetTimeSource.ps1 -help ?

Displays the help topic for the script

"@
$helpText
exit
}

if($help){ "Obtaining help ..." ; funhelp }


$hklm = 2147483650  # numeric representation of HKLM from WMI SDK
$strKey = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"
$strValue = "NtpServer"
$stdReg =  [wmiclass]"\\$computer\root\default:stdregprov"

$strTime = $stdReg.GetStringValue($hklm,$strKey,$strValue)

if($strTime.returnvalue -eq 0)
 { 
  $strOUT="$($strTime.sValue)" 
  funline([ref]$strOut)
 }
 ELSE
 { 
  $strOut="An error $($strTime.returnvalue) occurred"
  funline([ref]$strOut)
 }

Write-Host -foregroundcolor green "Time source on $computer"
Write-Host -ForegroundColor cyan $strout

Также интересно:

0
Голосов пока нет

Оставить комментарий