Get-EventLog and variables

Welcome Forums General PowerShell Q&A Get-EventLog and variables

This topic contains 2 replies, has 2 voices, and was last updated by

3 years, 9 months ago.

  • Author
  • #28494

    Topics: 5
    Replies: 8
    Points: 0
    Rank: Member

    I have a strange issue here:

    This works:

    $entrytype = "Error"
    Get-EventLog -LogName System -EntryType $entrytype}

    This also works:

    Get-EventLog -LogName System  -EntryType "Error,Information,Warning,SuccessAudit,FailureAudit"}

    However, this doesn't work:

    $entrytype = "Error,Information,Warning,SuccessAudit,FailureAudit"
    Get-EventLog -LogName System -EntryType $entrytype} 

    The error returned is:

    Cannot validate argument on parameter 'EntryType'. The argument "Error,Information,Warning,SuccessAudit,FailureAudit" does not belong to the set 
    "Error,Information,FailureAudit,SuccessAudit,Warning" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.
        + CategoryInfo          : InvalidData: (:) [Get-EventLog], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetEventLogCommand

    If you look at the error, I am providing exactly what it wants but still it doesn't like it for some reason, and I cannot figure out why.

    So in short, if I put more than 1 EntryType in a variable, it's not accepted anymore.

    Why o why?

  • #28495

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Your second example is using an array of strings:


    Your not-working is using a single string:


    The quotes prevent PowerShell from recognizing it as an array. Instead:


    Notice that the commas aren't in quotes.

  • #28498

    Topics: 5
    Replies: 8
    Points: 0
    Rank: Member

    Thanks, I was already thinking in that direction, but did not get the syntax right it seems.

The topic ‘Get-EventLog and variables’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort