MSGraph OData filtering on empty collections - powershell

I'm using the MS powershell modules for working with MsGraph, but the same rules/principles apply when providing a filter as to what you'd normally just put into the http query string.
I have the following which works okay and lists all 365groups that are teams:
Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')"
What I would like to acheive, without having to pull ALL groups and then filtering locally, is basically the opposite of the above, something like this:
Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x ne 'Team')"
But because I'm doing this against a collection, it throws.
Get-MgGroup_List: Unsupported property filter clause operator 'NotEqualsMatch'.
Now I've tried every which way I an think of to get this to work, I've tried looking for a set of operators that would effectivly filter if resourceProvisioningOptions is null/empty as a collection. But nothing I try will work, I just seem to get errors. Anyone have any ideas?
Thanks,
Tom

According to this resourceProvisioningOptions is not nullable and not filterable using null.
ne negation operators are supported only with advanced queries which means that you need to add -ConsistencyLevel "eventual" and -CountVariable or -CountVariable "<number>" (I'm not familiar with Graph API SDK for PowerShell) parameters
Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x ne 'Team')" -ConsistencyLevel "eventual" -CountVariable "100"

Related

Modifying Powershell LDAPFilter to add enabled=true

I've built a filter to look for a number of AD fields and properties that works well until I try to add a section looking for 'enabled -eq $true.'
Here is the filter that works successfully:
$filter = "(&(msExchMailboxguid=*)"+"(facilityID=12345)"+"(|(jobCodeID=0001)"+"(jobCodeID=0002)"+"(jobCodeID=0003)(jobCodeID=0004)"+"(jobCodeID=0005)"+"(jobCodeID=0006)))"
Get-ADUser -SearchBase "dc=acme,dc=corp" -LDAPFilter $filter
This works, and produces the correct AD user objects (four total).
But if I try looking for enabled accounts only, like so:
$filter = "(&(msExchMailboxguid=*)"+"(facilityID=12345)"+"(enabled=$true)"+"(|(jobCodeID=0001)"+"(jobCodeID=0002)"+"(jobCodeID=0003)(jobCodeID=0004)"+"(jobCodeID=0005)"+"(jobCodeID=0006)))"
It either fails with "the search filter can not be recognized," or it returns nothing at all depending on whether there are 3 or 4 closed parentheses. I've tried a bunch of variations like (enabled=true), (enabled -eq true) but none of them work.
The issue is that you are using an LDAP filter which is different than a native PowerShell filter and so has a different syntax. Even though most LDAP fields match pretty closely to their normal names, the Enabled field is not stored as a "normal" property (e.g. boolean true/false). Instead, it is held in a part of a bitmasked property userAccountControl. That means you have to use the "intuitive" filter:
(!(userAccountControl:1.2.840.113556.1.4.803:=2))
To filter out only the enabled accounts.
So that makes your filter for your example to become:
$filter = "(&(msExchMailboxguid=*)"+"(facilityID=12345)"+"(!(userAccountControl:1.2.840.113556.1.4.803:=2))"+"(|(jobCodeID=0001)"+"(jobCodeID=0002)"+"(jobCodeID=0003)(jobCodeID=0004)"+"(jobCodeID=0005)"+"(jobCodeID=0006)))"

PowerShell AzureAD odata v3.0 filter

So I am trying to fetch all sign-in logs that fails a particular Conditional Access that have been set in Report-Only mode.
The cmdlet is in preview and is unable to fetch all logs and then filtering using piping and powershell alone, so I am trying to query with a filter instead.
I currently have this query that runs successfully and returns lots of SignIn logs, but the results does not contains CA's with the result of "reportOnlyFailure" so something is wrong:
Get-AzureADAuditSignInLogs -Filter "AppliedConditionalAccessPolicies/any(c:c/id eq 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx' and c/Result eq 'reportOnlyFailure')"
I found your post, because I have the exact same problem.
My Powershell skills are pretty low but I may have found one problem, even if I have no idean how to fix it.
IsnĀ“t the part "and c/Result eq 'reportOnlyFailure'" searching for the result of all ConditionalAccessPolicies and maybe failing because of that?
Whould it be possible to do it like you would with a nested Where-Object? Something like this:
$($.AppliedConditionalAccessPolicies | Where-Object {$.id -eq 'XXX' -or $_.id -eq 'XXX'}).result -eq "reportOnlyFailure"
I dont know the full syntax for the filter but maybe you could replace
AppliedConditionalAccessPolicies/any(...
with something like
AppliedConditionalAccessPolicies/(id eq 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx')(...
I hope maybe this is usefull or you already found a solution.
If you got a solution I would be very thankfull if you could post ist.
Have a nice day,
Christian

Is there any way to filter sap.m.Tree?

I'm new to SAPUI5 component.
Is there a way to apply $filter to sap.m.Tree? It seems weird to me.
I'm currently using $filter options to limit the data from back-end (by using WHERE clause, came from $filter option), so I have to $filter to pass my parameter.
My controller :
this.oCharTable = this.getView().byId("CharTree")
var aFilterChar = new Filter("Matnr", FilterOperator.EQ , filter_base[2])
this.oCharTable.bindElement({
path: "/AUSP_ENTITY",
model: "AUSP_DATA",
filters: [aFilterChar],
parameters: {
NumberOfExpandedLevels : 2
}
});
and It's $batch payload :
GET AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27&$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
It depends on your data source:
if you have a odata v2, you can't filter on children. This is simply not supported by v2
if you have a odata v4, this is not supported by tree-binding. Good news, it on the roadmap https://github.com/SAP/openui5/issues/2728
if you preload all data an put it in a json model. You could filter as you like with vanilla js
Based on the given answer. You could just ignore v2 specification and filter in the backend as you want with any passed filter.
Oh, I think I found the solution - the problem is on backend!
Thanks to this answer, Using Suspend - Resume makes me send right GET request, like
../AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27%20and%20(Matnr%20eq%20%27SomeKindofMaterialHere%27)&$skip=0&$top=100
I changed my backend to select right values, and returning value to frontend.
For future leaders, who might read my question, I changed my backend to take not only take 1 option (this one, might be Matnr), but also take 'HierarchyLevel', which have to be taken care of.
In detail - I using $filter parameters to get data from CDS View, which can reduce the select result to resonable level.
so I redefine DPC_EXT Class, split up my $filter input, and put it into my parameter, and put result into result table.
TL;dr : If you using $filter on Tree View : check the 'return' backend. It might be problem in there.

Using where() node to filter empty tags in Kapacitor

Using Kapacitor 1.3 and I am trying to use the following where node to keep measurements with an empty tag. Nothing is passing through and I get the same result with ==''.
| where(lambda: 'process-cpu__process-name' =~ /^$/)
I can workaround this issue using a default value for missing tags and filter on this default tag, in the following node but I am wondering if there is a better way structure the initial where statement and avoid an extra node.
| default()
.tag('process-cpu__process-name','system')
| where(lambda: \"process-cpu__process-name\" == 'system' )
Sure it doesn't pass, 'cause this
'process-cpu__process-name'
is a string literal it TICKScript, not a reference to a field, which is
"process-cpu__process-name"
You obviously got the condition always false in this case.
Quite common mistake though, especially for someone with previous experience with the languages that tolerates both single & double quote for mere string. :-)
Also, there's a function in TICKScript lambda called strLength(), find the doc here, please.

Play Framework - find Object with "Or" in the query

It is possible to use "AND" while querying for Objects in Entity like
Post.find("byTitleLikeAndAuthor", "%hello%", connectedUser).fetch();
but is it possible to user "OR" while querying, like
Post.find("byNameOrEmail", name, email).fetch();
Thank you
Fixed!!
Use Post.find(" name = ? or email ?", name, email).fetch();
While using "where" in the query, it fails saying "unexpected token"
It is indeed possible to use "And" clauses when constructing objects, but I'm not aware of a possibility in simplified query to use "Or".
However, play can be used in many ways. Instead of writing :
Post.find("byNameOrEmail", name, email).fetch();
You can write :
Post.find("name = ? or email = ?", name, email).fetch();
using JPQL syntax.
It's not possible to use simplified query with or. To enable it you must change the implementation of findByToJPQL in the class play.db.jpa.JPQL. Wrote test and enhance the documentation and create a patch.
How ever you can use the JPQL.