Credential storing for automation

Hi All

This going to be difficult to explain but I will try convey my issue as best I can.

I have a powershell script that calls a REST API to backup a vCenter Server. The script gets triggered nightly via a scheduled task running on a Windows 2016 server (Win16). The task runs under a service account that has admin rights but does not have logon interactive rights on Win16.

I have a script that configures the scheduled task by doing the following.

  1. When one logons on to Win16 as an administrator and run the configuration script you are prompted to provide two sets of credentials, one for the service account under which the task runs and one for access to the vCenter REST API, backup account. I store the creds as two separate credentials objects
  2. I then invoke a "remote" PS session to the Win16 server under the user context of the service account and pass the credentials object through to the "remote" session.
  3. From within the remote session I then export the credentials object to, two separate files. These files are used in the backup script called via the scheduled task, to authenticate to the vCenter REST API.
The above works fine.

The issues I am having is when I try to automate this process for testing purposes. My automation process is basically as follows:

  1. Check if Win16 server has any vmware snapshots, if it does revert the snapshot, then delete, then create a new snapshot - at this point I have a fresh windows server.
  2. I then deploy my scripts and run through the configuration process - using Jenkins and Invoke-build pipelines, all done using invoke-command from the Jenkins servers.
  3. Now because I cannot respond to the prompts for the creds input, I bypass this step and just copy the xml files created in the manual process. and then create the scheduled task.
In both cases this is the same server and same service account trying to make use of the xml creds files. Just the manual process works and the automated process fails.

Any ideas why this is the case and how I could work around it.

Thanks

How are you doing this ? is it possible to show your code/sample code to make it more clear ?

https://superwidgets.wordpress.com/2016/08/05/powershell-script-to-provide-a-ps-credential-object-saving-password-securely/

install-module AZSBTools
help Get-SBCredential -Show