I'm running a PowerShell script from the command line using the following command: `powershell.exe -ExecutionPolicy Bypass -File .xyz.ps1`. I want to prompt for credentials the first time the script runs and then remember those credentials for future executions, provided the PowerShell window remains open. However, it keeps prompting me every time. Is that because each execution starts a new PowerShell process, resulting in no access to previously entered credentials?
3 Answers
Yes, every time you execute that command, it launches a new PowerShell instance which doesn’t remember anything from previous runs, including your credentials. That's why you keep getting prompted for them each time you run the script.
When you mentioned the snippet, I'd like to know how you're executing it. Are you using the Run dialog, Command Prompt, or directly from a PowerShell window? Also, is bypassing the execution policy essential for your script to function? That might also help clarify the situation.
If you're running the script from within an active PowerShell session, there’s a better way. Instead of starting a new instance, you can use the dot-sourcing method to call your script: `. .xyz.ps1`. This way, any variables you set (like your credentials) within the session will persist.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically