Reputation: 1364
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?
Upvotes: 2
Views: 1253
Reputation: 3236
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
Upvotes: 1