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
  • can encrypt the password if desired
  • does not need separate detection and remediation scripts
  • automatically provisions a local admin account
  • can remove any other local admin accounts if desired
  • can whitelist approved admin (groups)
  • 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.

8. If you want to display an encrypted password in Intune, generate a public and private key and configure the resulting values in gui.ps1 and leanLAPS.ps1

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.

190 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jonathan
Jonathan
2 months ago

Awesome work! Is there any way we can keep the 2 azure AD SIDs for global and local admins that get added when a machine is joined to azure while removing any other local admin? We want to keep the ability to use the local admin group via azure portal while removing any previous local admins. When running the script I notice my azure ad machines lose their global\local admin SIDS.

jonson
jonson
3 months ago

Nice work! I’ve upgraded your solution with encryption the password with public key, and sending it securely . it can then be decrypted with private key , so the password is never exposed in user’s computer, on the post to intune or in the intune itself. (and so there is no need to delete intune logs to cover up tracks 🙂

also found that some computers having error changing password with error 3221226252 .
i was able to resolve it by splitting the line where ConvertTo-SecureString happens, so i first create the secure-string and then change the administrator password .

Steven Walker
Steven Walker
7 months ago

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

Last edited 7 months ago by Steven Walker
Simon
Simon
3 months ago

Looks great, thank you.
We are soon to decommission AD and go Azure cloud only.
Can I confirm if this solution still requires AD in the way LAPS does?
i.e. I’m looking for a solution of local admin password management that will work without AD

Gold
Gold
7 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 »

Hubo Bomo
Hubo Bomo
1 month ago

First of all, thank you very much! We were looking for this solution 🙂 We modified it to encrypt the password, so there is no need to create the scheduled task during the Proactive Remediation. First, you generate and keep the private and public keys: ## Generate key pair $RSA = New-Object System.Security.Cryptography.RSACryptoServiceProvider(2048) $private = $rsa.ExportCspBlob(1) $private -join "," $public = $rsa.ExportCspBlob(0) $public -join "," Then, in the script you can add a function like below with your public key as a string separated by commas.     ## Encrypt Password using the Public key     Function Encrypt-Password ($password)… Read more »

Patrick
Patrick
1 month ago

Just a litle heads up

$onlyRunOnWindows10 = $True #buildin protection in case an admin accidentally assigns this script to e.g. a domain controller

[Environment]::OSVersion.Version.Major -ne 10

Windows Server 2016 and 2019 will report 10, so it will not prevent a server to run it.

Great solution BTW, thank you

Last edited 1 month ago by Patrick
Marko
Marko
4 months 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
6 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.

JTech
JTech
5 days ago

Hi, Love the script but, I seem to have one issue where it creates the local admin account as disable vs. enabled. Any one have any ideas as to why? or experience similar issues?
I tried adding :

Enable-LocalUser -Name “InsertAdminAccountNamehere”
at line 98 but no luck

Gary
Gary
5 days ago

Hi Jos,

Good work, I have tested and everything is working as expected.

I work for an MSP and would love to deploy this solution to our clients to replace on-premises LAPS as we complete cloud migrations. This isn’t something we are looking to sell, just a tool to use as a replacement for on-premises LAPS. I understand you need to give consent to allow us to use this tool before we do.

Thanks,
Gary.

Da_SyEnTisT
Da_SyEnTisT
27 days ago

I’ve been using this solution for a couple of weeks now. But I started seeing some endpoint gving me this Post-remediation detection output:

REDACTED

What could be causing this ?

This is the output from the gui tool

Local Username  : .\REDACTED
Password     : REDACTED
Password Changed : REDACTED

Stephen
Stephen
29 days ago

I have this set to run Daily and repeat every 30 days and have it assigned to all my devices. However, in the device status page I’m seeing it being run multiple times a day with different username’s associated with the status. This makes it very hard to determine what the current password is if I have to check 3-4 different outputs to determine the password. Any reason why I’d be seeing this?

GreeZdLightNin
GreeZdLightNin
1 month ago

I am getting this error when trying to run the GUI…any thoughts ?

lapsguifail.png
Jonathan
Jonathan
1 month ago

Hi Jos! Hope all is well! Been testing the new encryption option and running into an issue with the GUI. I loaded your old GUI I had working with the previous laps version without encryption and the old gui shows multiple logons if the machine had multiple users and also the different times the password was updated. The new GUI will only show 1 result and is the first result. Never any of the new password syncs show. I can see the passwords being updated in the intune portal. I made a fresh machine to test as well and same… Read more »

Patryk Wypych
Patryk Wypych
1 month ago

Does any one have instruction how to install this GUI?

Tristan
Tristan
2 months ago

Groeten!
The tool is great, thank you.
I have just one issue after implementing it:
I can’t execute elevated apps with AD admin accounts anymore.
A dialog box opens that the domain admin does not have sufficient rights to start the elevated process, ie. cmd.exe.
Elevating processes is now only possible by using the local admin account.
Is this behaviour a known issue?

VICTOR AL-HILFI
VICTOR AL-HILFI
2 months ago

Dear,

I have an issue, when I check I see that some laptops with one entry and others with two entries for the same laptop.

Do you have an idea how we can modify the script so it fixes this issue?

Note the two entries will work fine (one of them) but not the only one entry.

Thanks in advance

Maikel
Maikel
2 months ago

Hi,
great script, and it works nice, but I’ve one question.

when the script is running, I see the password in plain text in the registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IntuneManagementExtension\SideCarPolicies\Scripts\

after 5 min. the password is removed and changed to REDACTED.

Is it possible to change this faster?

djolenole
djolenole
3 months ago

Hello,

This works great.
I have only one issue, can’t remove AzureAD account account from Administrators group!?

If user account is added from AzureAD as local admin(AzureAD\Intunetest5) I am not able to remove it using this script(attached screenshot), it says: Principal Intunetest5 was not found.

However, I can do that if I run this script on the specific computer locally in Powershell ISE.

Log error:
<![LOG[error from script =Remove-LocalGroupMember : Principal Intunetest5 was not found.
At C:\Windows\IMECache\HealthScripts\2c2ccb13-58f8-41ea-bb92-e8ea3e96450b_4\detect.ps1:48 char:32
+ …   $res = Remove-LocalGroupMember -Group $administratorsGroupName – …
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo     : ObjectNotFound: (Intunetest5:String) [Remove-LocalGroupMember], PrincipalNotFoundExcepti 
  on
  + FullyQualifiedErrorId : PrincipalNotFound,Microsoft.PowerShell.Commands.RemoveLocalGroupMemberCommand

admin.JPG
Jithin
3 months ago

Is there any way to make the password change monthly instead of daily?

Mohan
Mohan
3 months ago

Thank you so much for making this Script

I would like to add some special characters in password , tried on line 26 by adding special characters
password generated ,but not working.

please suggest me.

Jens
Jens
3 months ago

Hello, we implemented your script in MS Endpoint manager. There is just one problem for us, when the script runs, it also puts a checkmark at “user must change password at next login”. Is there a way to avoid this by altering the script?
The Set-LocalUser has no syntax to disable this option for the local admin account.

Gerard
Gerard
3 months ago

Great solution, thanks Jos! 
I noticed that a protector has been added to make sure that the script only runs on Windows10 devices ($onlyRunOnWindows10). How can I add support for Windows11 devices?

Djordje
Djordje
3 months 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
5 months 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
5 months 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
5 months 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
5 months 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
5 months 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
5 months ago

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

Iggy
Iggy
5 months 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
5 months 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 5 months ago by Dylan
ashoka
ashoka
5 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
6 months ago

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

chris
chris
6 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
6 months ago

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

Lee
Lee
6 months ago

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

TheSCCMBoy
7 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
7 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
7 months ago

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

Ákos
Ákos
7 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
7 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 7 months ago by chris
Shane Lackey
Shane Lackey
7 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
7 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 7 months ago by Zach
rohgin
rohgin
7 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
7 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
7 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
7 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.

Hello
Hello
2 months ago

Hi,
this works great. I set the script to run every 1 hour to check logs frequently…However, it happens on some machines that scheduled task just stopped working and never clears the log file. Is there any way to troubleshoot this? I can’t even see it within missed runs using:
Get-ScheduledTask | Get-ScheduledTaskInfo | ? NumberOfMissedRuns -gt 0

Scheduled task is not listed there.