Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (2024)

Table of Contents
SharePoint Flow PowerShell Intune

Hey Flow Fans!

This week’s article comes from Max Fritz at SADA Systems, Inc.

Max is an Office 365 and EMS Architect at SADA Systems, Inc. He focuses on improving collaboration and simplifying implementation, and has worked with Office 365 for the past eight years. He is a self-proclaimed geek, passionate about a broad range of security and collaboration tools and can’t stop talking about the technology he loves.Max is the founder and president of the Minnesota Office 365 User Group, and holds MCSA and MCSE Microsoft certifications. Max can be found speaking at Microsoft 365 conferences all over the US.You can find Max on Twitter @theCloudSherpa (https://twitter.com/TheCloudSherpa), or on LinkedIn (https://www.linkedin.com/in/maxafritz/).

https://image.ibb.co/gAqprL/intune3.png

Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (1)

Background

For those organizations that have fully adopted the Modern Workplace and have gone “cloud only”, you are most likely using Windows 10 on your workstations and managing those workstations with Microsoft Intune. While Intune is good at managing settings (and always getting better), there are limited reporting options available.

One of the most common requests I encounter is to get the status of local admins on the machines managed by Intune. The below Flow will walk us through gathering that information and presenting it to an administrator.

The following steps will be a part of this process:

  1. Deploy a PowerShell Script from Intune
  2. Device gathers data and kicks off Flow using a REST API call
  3. Flow writes data to SharePoint
  • Flow subscription
  • Intune subscription
  • Windows 10 devices in Intune
  • OneDrive or SharePoint location to store Excel workbook

SharePoint

For this example, we’ll be using a SharePoint list to store the data, however, you can adapt the below steps and store the data in an Excel workbook if you prefer.

  1. In your SharePoint site of choice, go to Add an app.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (2)
  2. From the options, select Custom List.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (3)Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (4)
  3. Give your list a name. We’ll call ours “Local Admins.” Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (5)
  4. Navigate to your new list and add 2 columns named “Computer Name” and “User Name” by repeating the below steps:
    1. Click Add column.
      Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (6)
    2. Choose single line of text.
    3. Fill out the column name and click SaveAdvanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (7).
    4. Make sure to repeat for the second column.
  5. Add another column, this time of type Yes/No, called “Is Admin”:Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (8)
  6. Open the SharePoint List settings:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (9)
  7. Scroll down to Views and click on All Items.
  8. Under Columns, click the checkbox next to Modified. This will allow the modified date to show in our view.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (10)
  9. Scroll to the bottom and click OK.
  10. Your SharePoint list should now look like this:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (11)

Flow

  1. Navigate to https://flow.microsoft.com/ and log in.
  2. Get started by Creating a flow from blank
    1. Pro Tip: Create this as a Team Flow so your team can manage it with you!
  3. Select Search hundreds of connectors and triggers.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (12)
  4. Search for When a HTTP request is received, and select it as your Trigger.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (13)
  5. Under Request Body JSON Schema, enter the following:

{

“type”: “object”,

“properties”: {

“Device”: {

“type”: “string”

},

“User”: {

“type”: “string”

},

“IsAdmin”: {

“type”: “string”

}

}

}

Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (14)

  1. Select New step
  2. Search for and select Initialize variable.
  3. Fill out the fields as follows:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (15)
    We will need to refer to this Device/User combination a few times so the variable will help us throughout the Flow.
  4. Add a New step again of type Initialize variable.
  5. Fill out the fields as follows:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (16)
    1. To fill in the Value field, search for “false” in the Expressions menu:
      Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (17)
  6. Add a New step of type Get Items (SharePoint)
  7. Fill out the fields as following (customize the Site Address and List Name to match your SharePoint list):
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (18)
    This will allow us to see if there is an existing entry for the Device/User combination.
  8. Add a New step and select Apply to Each:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (19)
  9. For Select an output from previous steps, choose value:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (20)
  10. Click Add an action and find and select Set a variable.
  11. Fill out the fields as following (using the expressions menu to fill in “true”):
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (21)
  12. Now that we’ve determined if an item exists already, click New step at the bottom (outside of the loop), and choose Condition:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (22)
  13. Fill out the condition as follows:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (23)
  14. Under If yes (which indicates an item already exists with this Computer/User combination), add an action of Update Item from the SharePoint connector:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (24)
    NOTE: by selecting ID for Id above, Flow will automatically put this action in a loop. You can safely leave that (you should not try to remove the loop). The action will still only occur once.
  15. Under If no (indicating no item exists in SharePoint for this Computer/User combination), add another Condition, and fill out as follows:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (25)
    NOTE: Use the actual word “true”, not an Expression as in prior steps.
  16. Under the new Condition, under If yes (indicating the user is a local admin), add an action of Create Item from the SharePoint connector:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (26)
  17. Under the new Condition, under If no (indicating the user is not a local admin), add an action of Create Item from the SharePoint connector:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (27)
  18. Save your flow, and scroll back up to the top.
  19. For When an HTTP Request is received, you should now see a URL next to HTTP POST URL:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (28)
    1. Save that URL; you will need it in a later step.

PowerShell

  1. Create a PowerShell script with the following content and name it “CheckAdmin.ps1” (you can use NotePad if you prefer):
    1. Make sure to add your HTTP POST URL from above inbetween the quotes on the second line.

#The HTTP POST URL from Microsoft Flow

$URI = “” #ADD YOUR URL HERE

#Get Current ComputerName

$computer = $env:computername

#Get Current UserName

$CurrentUser = whoami

#Get User’s Local Group Membership

$CurrentUserGroups = whoami /groups

#Check if current user is a member of the Local Admins group

$CurrentUserAdmin = $CurrentUserGroups -like “*S-1-5-32-544*”

#If user is an admin

if ($CurrentUserAdmin) {

$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘true’}

#Start Flow

Invoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’

}

#If user is not an admin

else {

$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘false’}

#Start Flow

Invoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’

}

  1. Save the PowerShell script locally on your computer.

Intune

  1. Navigate to your Intune portal by going to https://portal.azure.com/ and selecting Intune.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (29)
  2. Select Device Configuration.
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (30)
  3. Select PowerShell Scripts.Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (31)
  4. Select New, and fill in the information:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (32)
    1. For Script location, navigate to the PowerShell script you saved earlier.

i.Pro Tip: Keep a backup copy of this script. Intune does not allow you to re-download it.

  1. Click on Configure, and match the following settings:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (33)
  2. Click OK, and then Create.
  3. On the next screen, click Assignments:
    Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (34)
  4. Click on Select groups
    1. At this point, select a group of Users that you want this script applied to.

i. It is important that the script is not applied to a group of Computers.

  1. Click Select, and then Save.

At this point your script will begin running for the users assigned. It could take 24 hours for data to start populating.

The way Intune handles PowerShell scripts means this will run a single time per user per logged in PC. This is great to collect a one time snapshot of local admin status, but if you want to run it again, just simply repeat the Intune steps above again! The Flow is already built to handle updates to existing list entries if you choose to run it multiple times.

Additionally, consider integrating the SharePoint list with PowerBI or alerting to get better visibility into this data.

Also, consider this solution for any data you want to gather from your Windows machines. You could grab application installations, disk health, and more! Just remember that every time this script runs on every machine, it will kick off a Flow, counting against your runs per month.

While not a perfect solution, hopefully, this gives you greater insight into your Intune-managed environment!

Thanks for reading!

Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (35)

Gabriel Hollandsworth

See more articles from this author

Advanced | Flow of The Week: Gathering Local Admin Status from Microsoft Intune - Microsoft Power Platform Blog (2024)
Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 5973

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.