• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 55
  • Last Modified:

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
    )
0
snyderkv
Asked:
snyderkv
  • 2
1 Solution
 
footechCommented:
[CmdletBinding()] has to be the first thing inside a function or script (though comments are allowed before).
[CmdletBinding()]

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
)
$api=New-Object -comObject "MOM.ScriptAPI"
$PropertyBag = $api.CreatePropertyBag()

Set-StrictMode -Version 3

Open in new window

[OutputType()] isn't anything.
1
 
snyderkvAuthor Commented:
Right on thanks again
0
 
footechCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now