PowerShell script to list all user of a group and output group name as well - powershell-2.0

Is there a script that can list all users of a given group recursively so it covers all nested groups and also lists the name of group (nested child group) that user is part of so i know the group that user is part of

Related

How to create a 'group' using calculated field

I've created groups to bundle similar values together, e.g. product names containing specific keywords. However, product names are always changing and I don't want to have to manually update the groups with new product names.
I would like to use a calculated field which has the "CONTAINS()" function (or something similar to this functionality) in the group in order to have it updated when new values are found. How can this be done?

Report on office groups without owner

Use case:
I need to create a report on office groups without owner. This happens when people leave the company and their account is deleted. Their groups live further, but eventually group expiration kicks in and somebody need to take action.
Question: What is the easiest was to create query in graph to filter groups that do not have an owner?
What I currently do is:
List all groups
Enumerate this list and look for groups where the owner array is empty:
https://graph.microsoft.com/v1.0/groups/{id}/owners?$select=mail
This returns an empty array when there are no owners.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(mail)",
"value": []
}
This, in theory, works, but takes ages as we have many 10 thousands of groups, so I am looking for a solution that makes this possible with one query. I also tried to filter the exprationDatTime property to limit results but query this doesn't seem to be supported. I mainly need groups that are due to expire.
There is no way how to get groups without owners with one query.
What you can do is to query all groups, expand owners and select only id of the group and id of the owner. It will minimize the response size.
Then iterate through the all groups and check for empty owners collection.
GET https://graph.microsoft.com/v1.0/groups?$expand=owners($select=id)&$select=id

Eager load associations when querying against association data

I have a model "User" which has a one-to-many relationship with another model "Membership". Membership has a field named "group" which has the name of a group. I want to query for all the User records that are in a particular "group" and eager load all "memberships" for each User returned.
Before I go further, I know that normally you would implement a "Group" model and make Membership a join table between User and Group and just query the specific Group for all its users. This example is a little contrived, but it represents the real case I'm working on.
Anyway, I tried the following query:
User.includes(:memberships).where(memberships: { group: groupname })
However, while this returns the correct users, it only eager loads the memberships that matches the query. To put it another way, if a user "Bob" is in the "red" and "blue" groups and I query for all "blue" group users, the user "Bob" is returned among the results but only his "blue" group membership is loaded.
Is there a way to do this with a single DB query AND eager load all memberships of each returned user?
In your example a single DB query is performed because there is a query condition on the association. Normally, includes would perform two DB queries, one to load the users and the other to load the associated memberships.
I paid attention to that because there is a solution that works performing two DB queries and it is fine (default ActiveRecord eager loading behavior)
User.preload(:memberships).joins(:memberships).where(memberships: {group: groupname})
Note: in the example the preload method is used instead of includes. That is for query conditions on the associated table to be applied only in the first query and to not affect the second query that preloads memberships. By default when there are no extra query conditions on associated table include works like preload.
The first query will fetch all the users having memberships of required group.
The second query will fetch all associated memberships without any extra condition.

How to retrieve parent groups in Google?

Google gives the ability to add a group to another group.
For example, if we add Group A to Group B and user xyz#abc.com is present under Group A, and when I try to retrieve the groups of the user xyz#abc.com using OAuth 2.0 using the API https://www.googleapis.com/admin/directory/v1/groups, it returns only Group A, and not Group B.
I would like to get Group B too in the response from Google, since Group A is a part of Group B.
Is there any way to do this? Does Google provide us with the list of all parent groups as well in OAuth?

Team Foundation Server: Assign work item to a group instead of an individual user

In TFS 2010, is there a way that I can assign a work item to a group (i.e. Developers or Designers) instead of an individual user? I'd also want to be able to create a query so that we can filter on that group as well.
Yes, you can. If your group is a member of the larger group that can be assigned to, then it will appear in the list of assignable users.
For example, a user hierarchy might be like this:
[Assignable Users]
[Developers]
[Project Managers]
Mark Avenius
Joe Schmoe
EDIT
As for the query, you can have the clause Assigned To contains #Me, which I believe will do what you want.

Resources