Jump to content

Recommended Posts

Posted

I have a PowerShell script which I am using to run some API calls and grab information which I am running manually. At the minute I am using the AccessKey & SecretKey hardcoded in the script. I want to be able to run it on a schedule so I want to be able to call the keys from the script and remove them from the script itself. I have tried using

ConvertTo-SecureString –AsPlainText –Force | ConvertFrom-SecureString | Out-File "C:\Scripts\File.ini"

and then using the following code

$SecretKey = Get-Content "C:\Scripts\File.ini" | ConvertTo-SecureString

But if I do this I get an error when I try and connect using the API. I am guessing the error is because the call does not recognize the secure string.

I have a feeling I'm going about it all wrong, but I'm not sure what I should be using so I can use the script on a shared server. I am new to API calls and I am at a loss to how I can use Access/Security Key securely. I have searched but am finding a solution using Azure which is not something I can do.

 

How can I store the API Keys securely so I can use them in scripts?

Posted

Without looking properly I can't comment on the syntax's of the conversion lines, but one thing I fell for when doing something similar was that I exported the string to file on one PC and was running the script on another; the encryption key for the conversion to/from secure string was therefore different.

 

There is a way to store the encryption key in a safe place so that the same key is used on both conversions if necessary - I had to do this as my script was executing on newly built PCs.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...