AIM: How to retrieve password using AIM CP and Windows Batch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Secrets Management Articles
2 min read
L2 Linker
No ratings
How can I retrieve a password from the CLIPasswordSDK and use it in a batch file?
 

Steps

Please refer to the below example script. You can set the environment variables either in the script or programmatically.
 
@echo off
 
REM Declare and set variables
set AIM_AppID=YourApp
set AIM_Safe=Your-Safe
 
REM Make sure the Object Name is the "Name" value of the account stored in EPV
set AIM_Object=Operating System-WinDomain-server.example.com-AccountName
 
set pwdcmd=C:\Progra~2\CyberArk\ApplicationPasswordSdk\CLIPasswordSDK.exe password /p "AppDescs.AppID=%AIM_AppID%" /p "query=Safe=%AIM_Safe%;Folder=Root;object=%AIM_Object%" /o Password
 
for /f %%A in ('%pwdcmd%') do set AIM_PW=%%A
 
if [%AIM_PW%] ==[] GOTO NOPWD
REM Place your code here for a successful password retrieval
echo "PWD is %AIM_PW%"
GOTO END
 
:NOPWD
REM Place your code here for error handling when password retrieval fails
Echo "Admin password was not fetched"
Exit /B 3
 
:End
Q:

How can I retrieve a password from the CLIPasswordSDK and use it in a batch file?

A:

Please refer to the below example script. You can set the environment variables either in the script or programmatically.

@echo off

REM Declare and set variables
set AIM_AppID=YourApp
set AIM_Safe=Your-Safe

REM Make sure the Object Name is the "Name" value of the account stored in EPV
set AIM_Object=Operating System-WinDomain-server.example.com-AccountName

set pwdcmd=C:\Progra~2\CyberArk\ApplicationPasswordSdk\CLIPasswordSDK.exe password /p "AppDescs.AppID=%AIM_AppID%" /p "query=Safe=%AIM_Safe%;Folder=Root;object=%AIM_Object%" /o Password

for /f %%A in ('%pwdcmd%') do set AIM_PW=%%A

if [%AIM_PW%] ==[] GOTO NOPWD
REM Place your code here for a successful password retrieval
echo "PWD is %AIM_PW%"
GOTO END

:NOPWD
REM Place your code here for error handling when password retrieval fails
Echo "Admin password was not fetched"
Exit /B 3

:End
Rate this article:
  • 1772 Views
  • 0 comments
  • 0 Likes
Article Dashboard
Version history
Last Updated:
‎02-01-2023 09:11 AM
Updated by: