Get-EventLog and variables

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?

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.

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