2

Given script like this :

Get-ADPermission -Identity "Mark Adam" | where {$._ExtendedRights -like "*Send-As*"} -and -not {$_.Users -like "NT AUTHORITY\SELF"}

Here I tried so far, still no luck.

var CommandGetAdPermission = new Command("Get-ADPermission");

CommandGetAdPermission.Parameters.Add("Identity", Identity);       

var CommandWhere = new Command("Where-Object");

ScriptBlock filter = ScriptBlock.Create("{$_.ExtendedRights -like \"*Send-As*\"} -and -not {$_.User -like \"NT AUTHORITY\\SELF\"}");

CommandWhere.Parameters.Add("FilterScript", filter);

pipeline.Commands.Add(CommandGetAdPermission);
pipeline.Commands.Add(CommandWhere);                     

psh = pipeline.Invoke();
errors = ps.Streams.Error.ReadAll();

Return error as below :

The term 'Where-Object' 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.

Do I do something wrong?

1
  • Can you post the part where you create the runspace for your pipeline? Commented Sep 1, 2016 at 12:25

1 Answer 1

1

Your syntax is wrong. In case of complex filtering (i.e. more than one criteria) you want to put whole filter criteria in script block like this:

Get-ADPermission -Identity "Mark Adam" | Where-Object {$_.ExtendedRights -like "*Send-As*" -and $_.Users -notlike "NT AUTHORITY\SELF"}

There is also a typo with

$._ExtendedRights 

while it has to be

$_.ExtendedRights
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.