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 admins or groups from AzureAD or Active Directory
  • 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

9. If you don’t want LeanLAPS to remove certain preapproved admins or groups as admin, make sure to configure the $approvedAdmins variable.

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

Troubleshooting

If your passwords don’t rotate correctly, check https://smsagent.blog/2021/04/27/a-case-of-the-unexplained-intune-password-policy-and-forced-local-account-password-changes/

Subscribe
Notify of
guest

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

425 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jonathan
Jonathan
1 year 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.

dfitelw
dfitelw
8 months ago

Microsoft makes this such a pain in the neck. Then to add insult to injury your solution requires additional licensing above what we already have, just to implement a feature that should already exist.

SIGH.

jonson
jonson
1 year 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 .

Jithin
Jithin
1 month ago

Updated to the latest script and getting this output now……

{“Username”:”user”,”SecurePassword”:”4f*=f8zDxR”,”Date”:{“value”:”\/Date(1665494623434)\/”,”DisplayHint”:2,”DateTime”:”Tuesday, October 11, 2022 9:23:43 AM”}}

it used to be like this before……

LeanLAPS current password: a0!i4Yay(G for user, last changed on 04/07/2022 17:01:01

Anyway to change it back to old view?

1.png
Simon
Simon
1 year 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
1 year 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
1 year ago

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

Last edited 1 year ago by Steven Walker
Jannis
Jannis
3 months ago

Thanks for the script. I have adapted the script so that our helpdesk does not have to search for the device name via the web, but can use it directly in the GUI.

 $user = Get-AzureADUser -SearchString $inputBoxUsr.Text
$devicenames= Get-AzureADUserRegisteredDevice -ObjectId $user.ObjectId -All $true | ft DisplayName
 

Then put the whole thing into the output box and link it to an additional button. Then you can search for a user and all linked devices will be searched in Azure AD. The device name can be copied out of there. 

Andrew
Andrew
1 month ago

Awesome solution, really appreciate all the hard work putting this together. I am running into an issue that I haven’t been able to resolve yet however. When I run the GUI and type in a device name, it shows the password for a completely different device. Any help in resolving this would be greatly appreciated!

David Smith
David Smith
1 month ago

Hi, nice work for this script. I’m just confirming that this output is correct as it is not the same as the output shown above? I assume this is for the GUI and serves the same result nonetheless for the remediation output.

{“Username”:”OurLocalAdmin”,”SecurePassword”:”xxxxxxxxxxxxxxxx”,”Date”:{“value”:”\/Date(1665462513995)\/”,”DisplayHint”:2,”DateTime”:”Tuesday, 11 October 2022 2:28:33 PM”}}

Josh
Josh
2 months ago

Thank you so much for putting this together! I am getting a strange error when using the GUI though. When I attempt to obtain the password for a particular device from the GUI, I receive the error Exception calling “PerformClick” with “0” argument(s): “Invalid JSON primitive:Invalid JSON primitive: LeanLAPS. Note that I named the proactive remediation script in Intune LeanLAPS. If anyone has any insight to this error it your assistance would be greatly appreciated!

Tawhid
Tawhid
3 months ago

can someone help with this ?

error.PNG
Hubo Bomo
Hubo Bomo
1 year 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 year 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 year ago by Patrick
Marko
Marko
1 year 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.

Kim
Kim
1 year 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.

Senior Feet
Senior Feet
1 year 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.

Daniël Vleeshakker
Daniël Vleeshakker
1 year 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.

Betti
Betti
2 days ago

Hello, what is it when the GUI does not find a device?
Message: “Device name not found or remediation did not yet run”
Am I missing permissions?
Post-remediation detection output are available.

YANIS
YANIS
10 days ago

HI, GETTING THIS ERROR
PLEASE HELP

Screenshot_68.png
Abrar Ali
Abrar Ali
25 days ago

Excellent script and makes my job a lot easier. However, initially I was running the script for user group everyday once and it was working fine. But later I changed it to daily and 7 days. Now most of the passwords in the Output are not working. Is there any way to investigate and troubleshoot as most of the computers are effected and it is causing severe issue.

Dave Smith
Dave Smith
1 month ago

Hi, Nice utility, however I am cautious about the output of the plain text password into the C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\AgentExecutor.log, which has NTFS ACLs as Everyone\RW and Users\RO?

Anas
Anas
1 month ago

Hi Jos, Great work on this, everything is superb!

Just that the script doesn’t run for some devices in my pilot group. No idea what’s causing the issue.

Also, can this work for any Managed Windows? Or just AAD Joined or HAADJ machines?

Thanks

Chan
Chan
1 month ago

Hi Jos,
Having an issue with the script removing AzureAD admins from the device. I only specified one global admin SID in the $approvedAdmins variable, but checking event viewer on my pilot group I see the following: Not removing S-1-5-21-xxxxx because of whitelisting. I have not included the above SID in $approvedAdmins, see the attached screenshots. Any idea what could be going on?

notepad++_9ApuSBQrmk.png
Mario
Mario
1 month ago

Hi Jos Sorry to ask again but I have a problem with leanLaps. I changed the minimum password length: $minimumPasswordLength = 15 Now I have the following problem: When the Admin get created he gets a 15-characters-password which worked fine. On the second run a 20-characters-passwort gets displayed in MDE. All local logs are correct as they say “Setting password for Admin1361 …” – “Password for Admin1361 set to a new value, see MDE”. But this new password is not working, and on this point also the old password no longer works. On the third run the same problem: a… Read more »

Griffin
Griffin
1 month ago

Hi Jos,

If the character ‘&’ is generated in a password, it’s displaying it as /u0026 in the post-remediation output. This is probably happening during the ConvertTo-Json part

Mario
Mario
1 month ago

Very helpful script, thank you for sharing. I tested this on our tenant and it is running nice. I have just one question about it: I can deactivate two type of local users: $removeOtherLocalAdmins $disableBuiltinAdminAccount Am I right that the disableBuiltinAdminAccount will deactivate the user “Administrator” which is built in after the Windows Installation? Am I right that the removeOtherLocalAdmins will remove the admins from the “Administrators”-Group? After running the script my own User (Intune owner of the device) was not in the “Administrators”-Group anymore. Which of this two settings removes the owner of the device? Can I prevent this… Read more »

Paulo
Paulo
1 month ago

Hello, this new update doesn’t allow consult the password with the new script. Any suggestion to solve the problem?

Paulo
Paulo
1 month ago

Hello, first of all thank you for the fantastic work.

I have a doubt where I can find the TaskName “leanLAPS_WL”?

I tried the policy and after I delete from Intune portal, next deleted the scripts from: c:\windows\IMEcache\Healthscripts but the script is still running, I search in task scheduler, but I don’t find anything?

Max
Max
1 month ago

Hello and thanks for this awesome Script.
We have the problem that the remedation is applied, whenever a (unique) user logs in to the device. The config is applied to a device group, so that is quite strange or is this intended?
We noew have to quickly look which user has logged in the last time, so we get the current password.
I would appreciate your help!

Gr3g
Gr3g
1 month ago

Hi Jos,
it works really great!! awesome job.
I have a question : The hour of “password change” is not correct, i have 2 hours less…
how I can correct this ? I’m not too comfortable with powershell.

Mike Jones
Mike Jones
1 month ago

Great work! In the first run it worked absolute fine, now we adjusted the password length and tried to re-run the script, but the Pre-remediation detection output throws the following error message now: Something went wrong while processing the local administrators group The Object reference was not set to an object instance.
Can anyone help me out here? I followed the instructions above until step 7.

Cors
Cors
2 months ago

This script has been working great for us. Recently devices are reporting in the “Post-remediation detection output” REDACTED instead of the password. Any idea what causes this?

leanLAPS_Redacted.png
Tim
Tim
2 months ago

Love it!! However, one question. We’re currently testing this out on a small collection, and we everything works as expected. However, the P/R report shows the devices have issues. Our other P/R scripts run, and then report back in no issue after remediation. Is this expected as the detection part? Image attached.

LAPS.png
Chan
Chan
2 months ago

Trying to use the GUI to decrypt the password but I get the error below. I copied and pasted the public and private keys from my clipboard when they are generated from the generatkeys.ps1. I’ve also tried to copy/paste them into a txt editor and made sure they were in UTF-8 format. Anyone else run into this issue? See the end of this message for details on invoking  just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Management.Automation.MethodInvocationException: Exception calling “Decrypt” with “2” argument(s): “The parameter is incorrect. ” —> System.Security.Cryptography.CryptographicException: The parameter is incorrect.   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32… Read more »

Kotresha
Kotresha
2 months ago

HI, We have deployed LeanLaps to all the devices in our organisation and it was working well with out any issues but suddenly LeanLaps stopped working to all user devices and giving same admin password for all user devices! Please advise on this

Moshe Razlan
Moshe Razlan
2 months ago

I have the following issue with all the devices, can someone help ?

Screenshot 2022-09-20 120229.jpg
Tim
Tim
2 months ago

Running into an issue with the GUI – I am currently a GA (via PIM) and getting a crypto error. Any thoughts?

LeanLAPS-Error.png
Cin
Cin
2 months ago

Great script. It works great till encounter an issue with password. We set the password update at every 180 days from Intune. The users are getting error with below prompt way before 180 days. Errro: “account restriction are preventing this user from signing in for example: blank password arent allowed, sign-in times are limited, or a policy restrtiction has been enforced” Admin has to remote in user machine and reset the password for local admin user in order to make it work. Also is it possible to force cahnge password from Intune on this local admin user? Thank you for… Read more »

trackback

[…] Doc about Proactive RemediationsProactive Remediations Solutions:LeanLaps by Jos LiebenUnpinning the Microsoft Store by Andrew TaylorUpdate Lenovo BIOS by Damian van RobaeysOther posts by […]

Jun
Jun
3 months ago

we are now running issue on our LEANLAPS, input device name is resulting a different device name

LeanLaps_Capture.PNG
Mard
Mard
3 months ago

Just want to ask we are now seeing different result when we try to get a password of a computer.

Richard
Richard
3 months ago

encrypt the password or not ?
The communication between the client and intune should be already enrypted (ssl) right ?

So the only benefit with enryption is the password isnt plain text in intune correct?

Chris
Chris
3 months ago

Quick question, As many here sometimes I have computer with 2 entries. I first log with user A and a new entry is created. After sometime a new user login on the same computer and a 2nd entry is created. Problem is the second entry password requires a password change. Also the first entry “User A” is always re-created. So I have 2 entries User A and User B. But only password from User B works (fine for me), but why is User A still created as he doesn’t log anymore in the device? This always happen if we have… Read more »

mynamee
mynamee
4 months ago

I receive the following when running gui.ps1: (thoughts anyone) See the end of this message for details on invoking  just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Management.Automation.CmdletInvocationException: HttpRequestError —> Microsoft.Intune.PowerShellGraphSDK.PSGraphSDKException: HttpRequestError —> System.Net.Http.HttpRequestException: 400 Bad Request {“error”:{“code”:”UnknownError”,”message”:”String policy id is invalid. Provided id: 00000000-0000-0000-0000-000000000000″,”innerError”:{“date”:”2022-08-02T12:42:21″,”request-id”:”8d4d752e-9ae3-4002-b1c7-62595b898033″,”client-request-id”:”8d4d752e-9ae3-4002-b1c7-62595b898033″}}}   — End of inner exception stack trace —   at Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.ODataCmdletBase.Run()   at System.Management.Automation.CommandProcessor.ProcessRecord()   — End of inner exception stack trace —   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)   at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame)   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary2 functionsToDefine, List1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object… Read more »

Adam
Adam
4 months ago

Good morning,
We’ve had this working fine for months, but all of a sudden the “Post-Remediation” output has started returning “REDACTED” for > 75% of devices.
Any idea what would’ve caused this?
Thanks

graham
graham
4 months ago

Hi, I Wonder if anyone can help.

We have Intune setup to rename the built in admin account automatically as part of profile setup. It also sets the Local Admin group users up using a custom xml file in Intune.

I would like to introduce laps for security.

So in reality I only need the script to set the account to enabled, PW never expire, account never expire and to rotate the password then output to Intune. Could anyone help me change the script to achieve this please?

Neeraj Sharma
Neeraj Sharma
4 months ago

Everything is working we can show password but password not change after 1 hours automatically.

Ricky
4 months ago

Anyone have ideas on how to run the gui.ps1 on an Android? I’ve looked up some guides for running powershell via the Userland app, but I doubt that will allow for the GUI to work.

Adam
Adam
5 months ago

Hi,

Great solution this, the one issue I seem to have is the sync’s. So I set the remediation to every hour, however the password remains the same the next day. Does it need a reboot for this to kick in? If so, could this become unsafe if the user could potentially have the local admin password until the device is rebooted?

Thanks,

A

Lauri
Lauri
5 months ago

I’ve noticed LAPS has stopped working. Been like this for a few weeks now. It does not actually run on the device. There are no Pre or Post-remediation errors.Seems the script is running somewhat successfully but I can’t use the password.I can see it is not running every hour…even after device syncSome devices that have just been synced show the last run a few days ago. But that is not the main issue I guess, when I try to use the password it does not accept it. Any suggestions? Not sure if Windows has changed something or some other thing… Read more »

Arun
Arun
5 months ago

can you please explain how to create GUI.

Aaron Hall
Aaron Hall
5 months ago

This is a fantastic solution that I’d love to implement in my organization. However, my organization does allow a rather extensive list of users with legitimate needs to have admin rights (at least temporarily), and we’re not ready to implement a more robust solution (yet). As such, maintaining the list of SIDs is exhausting, since the list often changes. In my scenario, the users are maintained in two groups synced to AAD from AD (one for permanent admin rights and one for temporary 5 day rights). In the old days, the groups were GPO added to ALL workstations (because of… Read more »

Chris Wright
Chris Wright
5 months ago

Hello I get the following error when running the GUI as Intune Administrator or Service Desk users.

************** Exception Text **************
System.Management.Automation.CmdletInvocationException: HttpRequestError —> Microsoft.Intune.PowerShellGraphSDK.PSGraphSDKException: HttpRequestError —> System.Net.Http.HttpRequestException: 401 Unauthorized
{“error”:{“code”:”UnknownError”,”message”:”{\”ErrorCode\”:\“Forbidden\“,\”Message\”:\”{\\r\\n \\\”_version\\\”: 3,\\r\\n \\\”Message\\\”: \\\”An error has occurred – Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 – Activity ID: a4df0c5f-56e7-4362-98f5-83b96629d82a – Url: https://fef.msub05.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/deviceHealthScripts%28%2710c1b6a4-add4-4334-b8fe-7820c2362ab4%27%29/deviceRunStates?api-version=5022-04-14&$filter=managedDevice%2fdeviceName+eq+%27weazl-gyr4hr2%27&$select=postRemediationDetectionScriptOutput&$expand=managedDevice(%24select%3ddeviceName%2coperatingSystem%2cosVersion%2cemailAddress)\\\”,\\r\\n \\\”CustomApiErrorPhrase\\\”: \\\”\\\”,\\r\\n \\\”RetryAfter\\\”: null,\\r\\n \\\”ErrorSourceService\\\”: \\\”\\\”,\\r\\n \\\”HttpHeaders\\\”: \\\”{\\\\\\\”WWW-Authenticate\\\\\\\”:\\\\\\\”Bearer realm=\\\\\\\\\\\\\\\”urn:intune:service,c3998d6e-2e37-4c56-87b5-7b444ee1cb26,f0f3c450-59bf-4f0d-b1b2-0ef84ddfe3c7\\\\\\\\\\\\\\\”\\\\\\\”}\\\”\\r\\n}\”,\”Target\”:null,\”Details\”:null,\”InnerError\”:null,\”InstanceAnnotations\”:[]}”,”innerError”:{“date”:”2022-06-09T08:11:05″,”request-id”:”a4df0c5f-56e7-4362-98f5-83b96629d82a”,”client-request-id”:”a4df0c5f-56e7-4362-98f5-83b96629d82a”}}}
  

If I run with a GA account it works fine. Any ideas what permission is required?

Last edited 5 months ago by Chris Wright
Nate
Nate
5 months ago

I noticed just recently that this is reporting a new password but the devices themselves aren’t having the reported passwords applied to them.

Craig
Craig
6 months ago

If I delete a device from intune, how do I then use the LAPS tools to log into the device with the local admin account? It seems the LAPS data also deletes when the device is deleted.

Paul S
Paul S
6 months ago

it looks like the script query you need to run to get a list of your remediation scripts no longer works (at least not for me) it just returns an error. https://graph.microsoft.com/beta/deviceManagement/deviceHealthScripts

dj56
dj56
6 months ago

Generally this works very well, occasionally the device will not accept the admin password. What do you recommend we do to troubleshoot when that happens?

whoisasking
whoisasking
7 months ago

Hey Jos,
This works like a charm.
Can you please explain the purpose of line 177 and what it does?
“$res = Set-Content -Path $markerFile -Value (ConvertFrom-SecureString $newPwdSecStr) -Force -Confirm:$False”?
Why is the script writing to temp?
Thanks again for the awesome script.

David Taylor
David Taylor
7 months ago

Great concept! I tested this initially with no encryption. I also upgraded your solution by converting the .ps1 to an .exe by using a PS1 to EXE generator and included an icon for the app. I did this to prevent the script from being modified or changed by inexperienced support personnel. After my initial test, however, I tried using the encryption process but I am having issues when attempting to encrypt the password. I have configured the private and public keys in their respective areas of the scripts. The password is encrypted into MEM, but when running the gui.ps1 script… Read more »

Screen Shot 2022-04-06 at 11.39.39 AM.png
Alex
Alex
8 months ago

Great work! Thank you!

But I noticed that built-in administrator doesn’t disable if I set up $disable Builtin Admin Account = $True

Where can be a problem ?

Chad
Chad
8 months ago

Hi! I’m utilizing this within my company. I’m getting the incorrect username and password error when attempting to use the local admin account. This is some pretty great stuff and any help will be appreciated!

Maximiliano Morsia
Maximiliano Morsia
8 months ago

What kind of rights are needed to run the GUI.ps1 script? I get the request to login with my admin account, but seems like my credentials aren’t enough to run it.

Last edited 8 months ago by Maximiliano Morsia
Maximiliano Morsia
Maximiliano Morsia
8 months ago

Thanks! This is very useful! I’m trying to implement this in our environment, however I noticed the Local admin created by the script has the tendency to recheck its “User needs to change password at next logon” setting every now and then, thus making the password useless. Any advice on that?

Prajwal
Prajwal
9 months ago

This is a great solution, is there a way can we get the logs for audit purposes, who used the passwords and when on which device did they use something like this?

Jon
Jon
10 months ago

Works the 1st time it runs but after that the script Pre-remediation detection output says it failed because the specified local admin account already exists. Is anyone else having this issue? Do I need different detection and remediation scripts?

Moshe Razlan
Moshe Razlan
10 months ago

Hi I have an error with the GUI , can you help ?

LeanLapsError.jpg
MatthewC
MatthewC
10 months ago

Hello!
Ive been trying to use your script. It seems towork but when i go to Post-Remedition Detection output all I get is the attache screenshot with a string of numbers….all i changed in the script was the admin account name and $minimumPasswordLength = 10 not 21
Am i doing something wrong?

Cheers

Owen
Owen
10 months ago

Jos, this is amazing and working flawlessly for locally created user accounts, any thoughts on how to remove the AzureAD\Username accounts? getting the following errors about the account not being found.

localadminRemoval3.png
JTech
JTech
10 months 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
10 months 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
11 months 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
11 months 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
11 months ago

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

lapsguifail.png
Jonathan
Jonathan
11 months 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 year ago

Does any one have instruction how to install this GUI?

Hello
Hello
1 year 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.

Tristan
Tristan
1 year 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
1 year 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
1 year 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
1 year 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
Jithin
1 year ago

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

Mohan
Mohan
1 year 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
1 year 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
1 year 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
1 year 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 year 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 year 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 year 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 year 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 year ago

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

Iggy
Iggy
1 year 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 year 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 year ago by Dylan
ashoka
ashoka
1 year 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
1 year ago

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

chris
chris
1 year 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
1 year ago

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

Lee
Lee
1 year ago

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