Connecting to CRM using Button on Universal Dashboard

Hello,

I have a powershell script which connects to CRM using connect-crmonlinediscovery -interactive mode command.
It works fine when ran from powershell terminal however when i try to connect via button click from universal dashboard it does not open dialog box to enter credentials to connect to CRM
When script rans directly I get a dialog box which provide list of environments after entering the credential.
I need to execute the script from universal dashboard which will import my CRM solutions.
Please help

You cannot use an interactive logon like that.

The script is running as a process on the server so the connection is initiated from the server to your CRM. So if an interactive login prompt were to appear it would do so on the server.

You are going to either store the credentials in PU as a secret or have a param block at the top of your script to prompt for username/password and then create a credential object from tthem and pass that in.

Hello,

Thanks for the reply.
My apologies i am new to this. Will you be able to provide an example or snippet of how would i do this.
I will be importing solutions to multiple environments and was looking to keep my script generic.
Will i be hardcoding my environment url as well or just the credentials?