0
Answered

Get a current entity count from Import script

Carol Wapshere 3 years ago in PowerShell connector • updated by anonymous 3 years ago 9

Is there a way to get a current count of entities in the Connector from a Powershell Connector Import script? I would like to add a check on the number of objects I've discovered, before I start adding or updating entities.

Affected Versions:
Fixed by Version:

Answer

Answer

Hi Carol,


In testing, I'm also finding some strange behaviour in counting EnumerableQueryable. I'm no PowerShell expert, but the only reliable way that I've found so far to do this is to wrap it in @(), i.e. @($components.ContextEntities).Count, but note that this most likely involves enumerating the entire context into an array, so I wouldn't advise it if you expect a very large number of entities.

Answered

Yes, using ContextEntities, although this isn't really the responsibility of the connector.

It's not so much responsibility as an extra check on the import, particularly in light of the issues around querying two O365 tenants from separate IdB connectors. If I get substantially more or less objects than expected I can abort the script.

I looked at Graph but couldn't see a simple way to use it with Powershell and I don't have a lot of time to do research - I gave myself an hour on it. If anyone has a sample of using Graph from a Powershel script to retrieve Office 365 users then I'd be happy to see it. Note that we're doing some extra steps in addition to licensing at UoN and the Powershell methods are suitable and already in production.


I tried $components.ContextEntities.Count() but that doesn't work - how do I get the entity count?


Import all entities from connector Office 365 Staff Connector failed with reason Method invocation failed because [System.Collections.Generic.KeyValuePair`2[[Unify.Framework.Collections.GroupedNameValueCollectionKey, Unify.Framework.Collections.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=84b9288cb2633de4],[Unify.Framework.IValue, Unify.Framework.Value.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=84b9288cb2633de4]]] doesn't contain a method named 'Count'.. Duration: 00:03:08.4656802

Searching answer

Hi Carol, Could you please attach or send the current state of the script including the $components.ContextEntities.Count() line that causes the exception from your previous comment?

(Scripted attached in email)
Hi Carol, Please try changing $components.ContextEntities.Count() to $components.ContextEntities.Count (no parentheses).

I think that was it - thanks!

Sorry spoke too soon, that doesn't work.


To try and understand what that ContextEntities thing is I put this in my script:


if ($Verbose) {$logger.LogInformation("O365 Staff: " + $components.ContextEntities.GetType().BaseType)}

if ($Verbose) {$logger.LogInformation("O365 Staff: " + (get-member -InputObject $components.ContextEntities | out-string))}


This is what I get. It's a System.Linq.EnumerableQuery and there is no Count method:


20160418,07:40:17,UNIFY Identity Broker,PowerShell Connector,Information,O365 Staff: System.Linq.EnumerableQuery,Normal
20160418,07:40:17,UNIFY Identity Broker,PowerShell Connector,Information,"O365 Staff:

TypeName:
System.Linq.EnumerableQuery`1[[Unify.Product.IdentityBroker.PowerShellEntity,
Unify.IdentityBroker.Entity.PowerShell, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=84b9288cb2633de4]]

Name MemberType Definition
---- ---------- ----------
CreateQuery Method System.Linq.IQueryable IQueryProvider.CreateQuery(Sy...
Equals Method bool Equals(System.Object obj)
Execute Method System.Object IQueryProvider.Execute(System.Linq.Exp...
GetEnumerator Method System.Collections.Generic.IEnumerator`1[[Unify.Prod...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ElementType Property type ElementType {get;}
Expression Property System.Linq.Expressions.Expression Expression {get;}
Provider Property System.Linq.IQueryProvider Provider {get;}


",Normal

Answer

Hi Carol,


In testing, I'm also finding some strange behaviour in counting EnumerableQueryable. I'm no PowerShell expert, but the only reliable way that I've found so far to do this is to wrap it in @(), i.e. @($components.ContextEntities).Count, but note that this most likely involves enumerating the entire context into an array, so I wouldn't advise it if you expect a very large number of entities.