Quantcast
Channel: Service Management Automation – Trond's Working!
Viewing all articles
Browse latest Browse all 9

Powershell Workflow peculiarities #2: Using the “where” cmdlet

$
0
0

This isn’t actually a peculiarity, as the fact is very well documented when using workflows: You can’t rely on positional parameters in the “native part” of a PowerShell workflow. Most of the time that’s not a problem. However, some cmdlets are just so… familiar is the word I guess. Anyways.

This won’t work:

workflow whereTest
{
    $a = get-process
    $b = $a | where {$_.Name -match "Powershell"}
    $b
}

This will:

workflow whereTest
{
    $a = get-process
    $b = $a | where-object -filterscript {$_.Name -match "Powershell"}
    $b
}

Turns out, the filtering thing you use in your “where” cmdlet actually has a parameter, and it’s called “filterscript”. And you need to use it, or else you’ll get the sad message:

Where-Object : Parameter set cannot be resolved using the specified named parameters.
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.WhereObjectCommand
    + PSComputerName        : [localhost]

So there. Another case of not having to use InlineScript without actually needing to.

 


Viewing all articles
Browse latest Browse all 9

Trending Articles