Lightweight LAPS solution for INtune (MEM)

Managing local admin accounts using Intune has a lot of quirks, my tele-colleague Rudy Ooms has already written extensively about this. He also wrote a PowerShell solution to rotate a specific local admin’s password and had the genius idea of using Proactive Remediations (a MEM feature) to display passwords to admins, integrated / free in the Intune Console.

However, I felt I needed a more lightweight solution that;

  • does not require/modify registry keys
  • does not store the password locally
  • does not need separate detection and remediation scripts
  • automatically provisions a local admin account
  • can remove any other local admin accounts if desired
  • is language/locale-agnostic (e.g. ‘Administrators’ vs ‘Administradores’….)

Thus LeanLAPS was born!

To install/use:

1. head into the Proactive Remediations section of MDE and click Create script package:

2. Fill out some details:

3. Download and doublecheck the config of LeanLAPS.ps1 (e.g. configure if other local admins should be removed, what the local admin name should be and the password length). Make sure to use NotePad++ / that the file stays UTF-8 Encoded without a BOM.

4. Set both the detection and remediation script to LeanLAPS.ps1 and run it in 64 bit:

5. Assign to a group and deploy. By default it will run every day, but you can also let it run more or less frequently, which determines how often the password is reset (hourly in below example):

6. Deploy, and then click on the script package:

7. Go to Device status and add both output columns:

Congratulations, you can now see the current local admin passwords for all managed Windows 10 devices!

Note: if you wish to trigger a quick remediation, delete the correct keys under Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IntuneManagementExtension\SideCarPolicies\Scripts\Execution and Reports in the client’s registry, then restart the IntuneManagementExtension service and the remediation will re-run within 5 minutes.

RBAC

If you provide e.g. your helpdesk with the correct Intune roles, they will be able to see local admin passwords as reported by above solution:

GUI

The community, in the form of Colton Lacy, also added an optional GUI frontend for LeanLAPS which you could use for e.g. helpdesk staff:

https://gitlab.com/Lieben/assortedFunctions/-/blob/master/leanLAPS/gui.ps1
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

93 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Marko
Marko
4 days ago

Great solution, very nice! I have two questions: 

First, you wrote under 5. “Assign to a device group (user groups won’t work)” -> I tried it with a user group in my tests and it works with no issues. Could it be that your advice pointed to a earlier version of the tool?

Second, the copyright says “not for commercial use without written consent” -> what is the correct way the get this consent from you? We’d very much like to use your tool in our production environment.

Senior Feet
Senior Feet
3 months ago

As always, thanks for the amazing contribution! I was just about to set up the LAPS azure blob storage method I’ve read about elsewhere until I noticed your link on the user voice.

Just noticed one thing, we hot-desk and in my HAADJ environment if there is more than one user logged in to a workstation (switch user is enabled). The detection and remediation runs twice in succession, once against each active user. Not a big issue but just thought I’d flag it for your attention.

Gold
Gold
3 months ago

Thanks, Jos. This is awesome! I’m getting the following error – have updated the variable $localAdminName = “CustomAccount” New-LocalUser : A positional parameter cannot be found that accepts argument ‘True’. At C:\WINDOWS\IMECache\HealthScripts\601ec906-1ca6-4958-8678-089ca2e3217e_1\detect.ps1:53 char:19 + … ocalAdmin = New-LocalUser -PasswordNeverExpires $True -AccountNeverEx … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-LocalUser], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewLocalUserCommand C:\WINDOWS\IMECache\HealthScripts\601ec906-1ca6-4958-8678-089ca2e3217e_1\detect.ps1 : Something went wrong while processing the local administrators group Cannot validate argument on parameter ‘Member’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException… Read more »

Steven Walker
Steven Walker
3 months ago

That is very clever. I like it and see a lot of usage and need for this. Great job.

Last edited 3 months ago by Steven Walker
Djordje
Djordje
22 hours ago

Hello,

this is the best solution that I found! Tested it and it works great.
Is it possible for the end user to get his(local Administrator account) password somehow?

For example, we use LAPS in our internal environment and all users are able to read password ONLY for their computer that is valid for 30 days and after that the new one is generated.

Maarten
Maarten
1 month ago

Thank you Jos,
 
The scripted is great. tested it on a few machines. awesome.
 
The file %TEMP%\LeanLaps.marker will it hold the
password in plaintext? I see a remove-item further
along the script? How long will this file be present on the system? If no issues occur, will the file be deleted anyway?

Kim
Kim
1 month ago

Hi Jose,

How can I Make sure that the password always contain the password policy requirements. See below error on one of the machines:

Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.

Kim
Kim
1 month ago

Set-LocalUser : An unspecified error occurred: status = 3221226252 At C:\WINDOWS\IMECache\HealthScripts\a8a4d830-4dc2-4d9b-8ef8-6730be343fea_1\detect.ps1:114 char:30 + … ocalAdmin | Set-LocalUser -Password ($newPwd | ConvertTo-SecureString … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (LapsAdmin:LocalUser) [Set-LocalUser], InternalException + FullyQualifiedErrorId : Internal,Microsoft.PowerShell.Commands.SetLocalUserCommand

Jhony Andrade
Jhony Andrade
1 month ago

Hi, Jos.

Thanks for this great contribution.

How can I exclude azure groups (Azure AD joined devices or global Admin) ?.

Jhony Andrade
Jhony Andrade
1 month ago

Hello Jos.

What a pleasure this publication, grateful for the contribution.

I want to ask for your help, implement your solution with the option $ removeOtherLocalAdmins = $ True this will remove the Global Administrator and Device Administrator groups from azure.

1- You know how you can exclude these groups within the code so that you do not eliminate them. ?

2- Do you know how I can recover the azure Global Administrator and Device Administrator groups on the computers that were deleted?

Thank you very much for your help, Greetings

Optimus Grind
Optimus Grind
1 month ago

Can the license requirements for the proactive remediations component be ignored for this solution?

Iggy
Iggy
1 month ago

Hi Jos, thank you for such a fantastic solution!
Regarding the aspect of the passwords stored in cleartext in the log files, I’ve seen that in the past you suggested restricting FS permissions to the “Logs” folder.
What would be other alternatives to contain this risk?
Have you considered including this aspect to the solution?
Thank you in advance!

Dylan
Dylan
1 month ago

So I’m seeing several duplicate entries in the proactive remediation list using this method. Any ideas why? They also seem to have two different passwords.comment image

Last edited 1 month ago by Dylan
ashoka
ashoka
2 months ago

excellent contribution thank you very much
I have a question I have incorporated this solution but I do not know why it seems that runs with the user account and system account for each machine I have 2 runs with different passwords and in some log of the machines I’m getting the message WRITING what does this mean?

Vanier Francis
Vanier Francis
2 months ago

Hi, could you tell me if the password is transmitted cleartext or encrypted between the local pc and Intune?

chris
chris
2 months ago

Is there a way to test this locally first. Whenever I run it nothing happens. I’m running as Admin and with ExecutionPolicy set to Bypass.

All I get is the script running and finishing in 2 seconds the Event logs shows only shows that script started no other info or errors. Nothing changes in the local admins group.

Jason
Jason
2 months ago

Is there a reason you left 1 and special characters out of your password generation section of your script?

Lee
Lee
2 months ago

This solution is so elegant! I’ve only tested it on couple of machines but it looks promising. Thank you!

TheSCCMBoy
3 months ago

the solution is generally great but not secure. If you even use the task scheduler the attacker has the possibility to read the intunemanagementextension.log. I will think about to optimize the solution how we can query them correctly and transfer secure directly to the proactive remediation feature as post-remediation output.

kind regards
TheSCCMBoy

Peter JM
3 months ago

Hi Jos. Thanks for the post which is very useful indeed. On line 84 and 85 you use the PowerShell [ADSI] adapter to get the members of the local administrators group. When I tested the script with my regular domain account, these commands took 30-40 seconds or more to complete. Afterwards I got a friendly warning from the SOC that I had just queried the company AD for all accounts. So I would suggest using “Get-LocalGroup -SID S-1-5-32-544” and “Get-LocalGroupMember -SID S-1-5-32-544” instead. This might also solve some of the issues described in earlier comments. And yeah…we use co-management.

Vanier
Vanier
3 months ago

Solution works great. Is there a way to force an immediate password change outside of the scheduled time?

Ákos
Ákos
3 months ago

RBCA pic is just crashed/missing; how could I define a custom role for only seeing this attribute? Not having GA and even not Intune Admin role.

chris
chris
3 months ago

Great post. Is there a way to specify a local admin account to remove. I only want to remove the “administrators” account an leave all others alone.

Also it only seems to run on 1 device in the group I selected. The 1 device is the first device I setup and added the group any additional devices it doesn’t run on. Event log has no logs, other device has been rebooted and Intune sync’d multiple times.

Last edited 3 months ago by chris
Shane Lackey
Shane Lackey
3 months ago

Hello Jos,

I keep getting this in the event log.
Something went wrong while processing the local administrators group An error occurred while enumerating through a collection: Call cancelled.

Any ideas?

Zach
Zach
3 months ago

This is great! Thank you for your hard work! This is just what I need!

I’m getting an error however:

Something went wrong while processing the local administrators group Cannot bind parameter 'Member'. Cannot convert the "\\COMPUTERNAME\root\cimv2:Win32_UserAccount.Domain="COMPUTERNAME",Name="Administrator"" value of type "System.Management.ManagementObject#root\cimv2\Win32_UserAccount" to type "Microsoft.PowerShell.Commands.LocalPrincipal".
Last edited 3 months ago by Zach
rohgin
rohgin
3 months ago

Hi Jos,

I can’t find the setting to change the maximum days between a password reset.

Is it just me or?

With regards,

rohgin

Håvard Pettersen
Håvard Pettersen
3 months ago

Hi and thank you for this elegant solution.
I downloaded the script today and test but get the same error as mention before;
Something went wrong while processing the local administrators group Cannot validate argument on parameter ‘Member’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

Anders
Anders
3 months ago

Awsome feature! But all I get is “Something went wrong while processing the local administrators group An error occurred while enumerating through a collection: Call cancelled .”
No further info…

Daniël Vleeshakker
Daniël Vleeshakker
3 months ago

Hi Jos,

Great, thanks for this!

I’ve tried to use the script, but it fails at my machines on creating the user when it does not exist.

The error is: Cannot validate argument on parameter ‘Member’. The argument is null or empty. Provide an argument that is not null or empty and try again.

When running the scripts manually and asking the value of $localadmin it’s empty.