lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

HowTo: New-SerchFilter in pipeline #322

Closed JRAndreassen closed 1 year ago

JRAndreassen commented 1 year ago

What's going on?

Hi...

I'm trying to do a recursive search with a searchfilter.. This does not work, since it only gets the direct descendants

  $retVal = $Local:filter | Get-Group -ParentId $ObjectParent.Id -Recurse:$recurse
  $retVal = $ObjectParent | $Local:filter | Get-Group -ParentId -Recurse:$recurse
+  $ObjectParen | $Local:filter | Get-Group  -Recurse:$recurse
+                 ~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

Is there a way to pass the parent object directly ? Like

  $retVal = $Local:filter | Get-Group -Parent $ObjectParent -Recurse:$recurse

Thanks JR

Due Dilligance

lordmilko commented 1 year ago

Hi @JRAndreassen,

Assuming the value of $recurse is $true, do you get the results you expect if you instead do

$ObjectParent | Get-Group -Filter $local:filter -Recurse:$recurse

The Get-Group cmdlet allows you to specify several potential values by pipeline input

In your case, it seems like you want to specify both a parent (-Probe or -Group) and a -Filter. Only one of those can be specified by pipeline input, so for the other you will need to pass the value to the parameter directly

Are you able to advise if this resolves your issue?

JRAndreassen commented 1 year ago

Hello again @lordmilko ...

That was a quick turn-around...

Outstanding... That does indeed take care of the problem...

Thank you Sir... :)