Avatar of snyderkv
snyderkv
 asked on

Powershell error for NTP time offset

EE,

I pasted a piece of code below but get an error seen here. It's part of an NTP time snippet that alerts when the offset exceeds a threshold but this is the piece that errors out. Please assist.

Thanks again

+     [OutputType()]
+     ~~~~~~~~~~~~~~
Unexpected attribute 'OutputType'.
+     Param (
+     ~~~~~
Unexpected token 'Param' in expression or statement.
+         [String]$Server = "domain.com",
+                           ~~~~~~~~~~~~~~~
The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedAttribute

This is the code.

$api=New-Object -comObject "MOM.ScriptAPI"
$PropertyBag = $api.CreatePropertyBag()

Set-StrictMode -Version 3

    [CmdletBinding()]
    [OutputType()]
    Param (
        [String]$Server = "Domain.com",
        [Int]$MaxOffset = 1000,     # (Milliseconds) Throw exception if network time offset is larger
        [Switch]$NoDns               # Do not attempt to lookup V3 secondary-server referenceIdentifier
    )
Powershell

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
snyderkv

ASKER
Right on thanks again
footech

I should have verified before posting.  Some of my memory was faulty.

You can indeed have [OutputType()] before [CmdletBinding()] (or after, but both need to be before your Param() block).  But specifying [OutputType()] is essentially meaningless.  You're not saying anything about what the actual output type is, so it's the same as not having it.  Of course if you have something like [OutputType([string])] then it has meaning.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck