I'm writing a script that runs on a jump server and connects to a vCenter server. Right now, the credentials are stored directly in the script as plain text, which is a security risk if the file is accessed or exposed during a ransomware incident. What are better ways to store and retrieve the credentials securely, such as encrypted files, certificates, managed service accounts, or a secrets vault?
3 Answers
Certificate-based authentication can work well when the target service supports it. Store the private key in the machine certificate store with tightly restricted permissions, then allow the automation account to use it. A vault combined with certificate or managed-identity authentication is generally stronger than relying only on an encrypted credential file. Also restrict access to the script, enable auditing, avoid logging secrets, and rotate any credentials that cannot be eliminated.
Avoid putting passwords in scripts entirely when possible. A secrets manager such as Azure Key Vault, HashiCorp Vault for on-premises environments, or another enterprise password vault can provide controlled access, auditing, rotation, and runtime retrieval. The script should authenticate to the vault using an identity or certificate rather than another hard-coded password.
For a simple Windows-only setup, you can export a credential with PowerShell’s Export-Clixml and load it later with Import-Clixml. The encrypted file is tied to the Windows account and machine that created it, so it isn’t portable by default. It’s safer than plain text, but it still depends on protecting the account and host.
That helps. I’m also considering certificate-based authentication because I’m concerned about what could happen if the encrypted file were compromised.

If the environment is entirely on-premises, HashiCorp Vault sounds like a reasonable option. I’ll need to look at how to authenticate the scheduled task securely.