GetEventlog code question

This topic contains 3 replies, has 3 voices, and was last updated by  Olaf Soyk 1 year ago.

  • Author
    Posts
  • #59956

    Michael Dowds
    Participant

    I'm using PS 5.0 for this code:

     Get-Eventlog security -ComputerName 

    and putting my computer's name after -ComputerName, and getting this error:

    Get-EventLog : Missing an argument for parameter 'ComputerName'. Specify a parameter of type
    'System.String[]' and try again.
    At line:1 char:23
    + Get-Eventlog security -ComputerName
    + ~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-EventLog], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.GetEventLogCommand

    The code is from PS in a Month of Lunches, 2e, page 31.

    I'm not understanding why the code isn't working as written in the book, nor am I understanding what the error is, as I should be opening the security log for my computer.

    Thanks for you help.

  • #59959

    Olaf Soyk
    Participant

    If you like run this cmdlet for your local computer you don't need the parameter -ComputerName. What's your computername?

  • #59961

    Ebru Cucen
    Participant

    What is your computername is a good question as it may have escape characters. Can you try this?

    Get-EventLog Security -Computer $env:COMPUTERNAME 
  • #59962

    Olaf Soyk
    Participant

    Ahhh ... I gues I got it. If you like to use the parameter -ComputerName you have to put your computername after the parameter name. Like this:

     Get-Eventlog security -ComputerName "MyComputerName"

You must be logged in to reply to this topic.