Share via

Help with Powershell Script - Removing User from AD group if found as a primary user for a computer in Endpoint

Corey Rabinowitz 1 Reputation point
2022-09-12T21:36:00.463+00:00

Hi - Hopefully this can be done:

This is a hybrid workplace. We have an AD group of users that is used just to get them setup with Autopilot, the group is synced to AAD. Once their laptop is setup, they need to be removed from that AD group.
Problem is, not everyone remembers to remove the users from that group and people are in there unnecessarily which gives them access to a vpn that they shouldn't be using in day-to-day.

So, trying to come up with a powershell script that does the following:

  1. Gets all of the users in the AD group
  2. Gets all of the windows devices that show autopilotenrolled is true for those users in the group
  3. For each user in the group where the device is autopilotenrolled that's true, remove them from the group in AD (I believe it has to be removed from AD, not AAD since it's synced).

The problem is the mix of getting info from AAD/Endpoint and trying to use that info to go back to AD.
Can someone come up with a powershell script that can do something like that?

Thanks

Community Center | Not monitored
0 comments No comments

1 answer

Sort by: Most helpful
  1. Limitless Technology 45,241 Reputation points
    2022-09-19T06:53:35.083+00:00

    Hello there,

    The PowerShell Get-ADGroupMember cmdlet is used to list the members of an Active Directory group.
    If you’re not sure what the group name is, you can issue the following command to list all Active Directory groups.

    Get-ADGroup -filter * | sort name | select name

    Get all the Autopilot profiles available in your Intune tenant, and display them in JSON format:

    Get-AutopilotProfile | ConvertTo-AutopilotConfigurationJSON

    ------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.