Need Help With with API credentials in my script

Hello,
I have built a script which is using an API to retrieve data from an application and put it in a CSV. I am looking to create a scheduled task so that it can run on a daily basis. Now whenever I open a new PowerShell session and run the script, it prompts me to enter my client ID & Client Secret. I want a way around this as the scheduled task I’ll create would open a new PowerShell session every time it runs. I have tried various methods like saving my credentials in a file and then retrieving the same using the script, however, every time I run it in a new PowerShell session, it asks me to enter the API credentials. Let me know if you require any other information I may have missed out. Thanks in advance!

Usman,
Welcome to the forum. :wave:t3:

How about sharing your actual code? :wink: Without that it will be nearly impossible to advise something meaningful. :man_shrugging:t3:

And please … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

(Sometimes the “preformatted text” button hides behind the gear symbol :point_up_2:t3: )

Hi Olaf,

Thank you for your response. I was working on this yesterday and was finally able to run the code without having to enter the credentials. I used a variable to store my credentials and called it in my code with the help of Microsoft.PowerShell.SecretStore module.

Anyway, highly appreciate your prompt response on my question. It’s feels wonderful to join such a helpful community.

Thanks again!

Hey, that’s really great. :+1:t3: :love_you_gesture:t3: How about sharing your solution anyway? That could help others comming here looking for help for the same or a similar issue. :wink:

Hey Olaf,

The solution lies in the below article,

Thanks!