|
Re: Newbie: filter rows with variable On May 14, 12:55 pm, "Roman Kuzmin" <z...@z.z> wrote:
> 1) I guess in this context $args is arguments of a script block {$_ -like
> "*$args*"} passed into Where-Object cmdlet (but, strange, all lines should
> be returned in your example, IMO...). Try this way:
>
> function foo
> {
> $myArgs = $args
> gc <.> | where {$_ -like "*$myArgs*"} | sort
> }
>
> foo '<pattern>'
>
> 2) Is this OK?:
>
> .\list.ps1 '@work'
> or
>
> .\list.ps1 "@work"
>
> --
> Thanks,
> Roman Kuzmin
Hi,
assigning $args to $myargs actually worked :-). Thanks for this.
Calling the script with @work or "@work" returns the error I mention
in the first post.
Calling the script with '@work' (singlequotes) does return the
expected output. But how should I "prepare" my $args so that I do not
have to specify the singlequotes in the parameter?
I tried
$myargs=$args
$myargs = "'"+$myargs+"'"
but that returns the same errormessage as earlier mentioned.
Thanks, |