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