I am trying to implement LAPS (Local Admin Password Solution) on our network and I am having issues integrating LAPS with the ADU&C right-click context menu. My goal is for our Helpdesk staff to be able to right-click on a computer object within ADU&C and force LAPS to reset the local Administrator password using a LAPS PowerShell script supplied with it. I understand that you cannot run PS directly from the ADU&C context menu itself but I should be able to create a batch file and have it run the desired PS script. Everything works correctly but the problem that I have is when I right-click a computer object in ADU&C and then launch the batch file from the context menu, it passes the computer name as a LDAP formatted string. I am trying to parse that string within the batch file itself and then pass the parsed string to PS but I haven’t had any success doing so.
Generally, the batch file that I am using (launched from the ADU&C adminContextMenu) is:
@echo off Title "Reset local Administrator password" For /F "tokens=2 delims==," %%A In ("%1%") Do Set CompName=%%%A PowerShell.exe -ExecutionPolicy Unrestricted -Command "Import-Module AdmPwd.PS; Reset-AdmPwdPassword" -ComputerName:%CompName% Set CompName=
An example of the string being passed to the batch file as the %1% command-line argument is (the quotes are part of the string also):
What I want to get out of the above string is the computer name itself (IT-SYSTEM), which would be all of text after the first = (equal) sign up until the first comma (so my delims are set for that and my token is 2). I want to store that in a new variable called CompName and then I should be able to pass that variable along to the PS command within the batch file. I’ve tried a few variations of the FOR command without success. I think my problem might be that the original string being passed to the batch file has quotes wrapped around it already. Is it possible to pick up the desired info within the above string using a batch file if the string being parsed already has quotes around it?
Thanks in advance