As mentioned above, a BASE64 string will be piped into your script, which includes the username and new password (among other data), which you will use to rotate the Windows Scheduled Task credentials.
Using the below snippet, we can take the piped input and use certutil to decode the BASE64 string. These will be saved to temporary files and cleaned up later, as is the custom in bat scripts, as certutil only accepts files as input.
jq can be used on the resulting JSON file to get the values of user and newPassword.
for /f "usebackq delims=" %%a in (`jq -r .user %json%`) doset"user=%%a"for /f "usebackq delims=" %%a in (`jq -r .newPassword %json%`) doset"newPassword=%%a"
Using Admin Credentials
To update the 'Log On As' property on a Windows Scheduled Task, you will need a credential with the appropriate permissions, such as an Administrator account.
When attaching a PAM script to a record, you have the option to add a Resource Credential that is passed to the Gateway as part of the BASE64-encoded JSON data. The above credential will need to be attached as a Resource Credential.
As many Resource Credentials can be attached to a PAM script, knowing the UID of the Resource Credential you have attached helps ensure your script uses the correct one to update the Service's 'Log On As' property.
We can use jq to access the attached Resource Credential and filter by the records UID.
set adminrecord=%temp%\adminrecord.tmpset adminuid=<Admin UID>jq -r ".[] | select(.uid == \"%adminuid%\")" %recordsjson% > %adminrecord%@REM pull the login, domainName, and password from the %adminrecord% JSON objectfor /f "usebackq delims=" %%a in (`jq -r .login %adminrecord%`) doset"adminuser=%%a"for /f "usebackq delims=" %%a in (`jq -r .domainName %adminrecord%`) doset"domainname=%%a"for /f "usebackq delims=" %%a in (`jq -r .password %adminrecord%`) doset"adminpassword=%%a"@REM Create the admin usermain by combining the username@domainnameset adminusername=%adminuser%@%domainname%
Updating the Scheduled Task
The schtasks command is used to update the desired Scheduled Task using the values you just extracted. In addition to the new credentials, you will need the Admin credentials from above.