Constructing a where-object from variables

so i’m trying to make a function that is going to go through a log and pull information out of it, and output it based on different things. I have, since starting to write this post, learned that scriptblock is a valid type of parameter to pass, but I’m still having trouble formatting it. So here’s where I stand.

function Check-Log() { param([scriptblock]$block) $logFile = import-csv $path -Delimiter "`t" | ? $block } Check-Log(Class -E "Host") 

I have attempted to encase the parameter in single quotes, and including the where-object as part of the scriptblock.

If I don’t include it in quotes (like it is aboce), I get an error:

The term ‘Class’ is not recognized as the name of a cmdlet, >function, script file, or operable program. Check the spelling of >the name, or if a path was included, verify that the path is >correct and try again.

The script runs, without errors, if I do $logFile = import-csv $path -Delimiter “`t” | ? {$block}

and pass the arg as where-object Class -E “host”

however, that is obviously wrong, and doesn’t produce any output.

submitted by /u/workerdrone66
[link] [comments]

Leave a Reply