

I will show you how to do it in two different ways and discuss why I prefer one method over the other. It soon became apparent that this was less than optimal when I needed to move a script from Dev\UAT into production because certain variables would need to be updated between the environments.įortunately, like most languages, PowerShell permits the use of parameters, but, like many things in PowerShell, there’s more than one way of doing it.


When I wrote this script, it was early in my days of writing PowerShell, so I simply hardcoded variables into it. However, I would prefer for the user to be able to enter the password along with the rest of the above line instead of having to be bothered with the prompt. After updating the script for the production environment, I then modified the subject line for any outgoing emails to include the new variable.Īt the time though, I wanted to do this in a better way, and not just for this variable, but also for the others I use in the script. PowerShell.exe -Command enter-pssession myUser -credential userName When I run this, it opens a dialog to prompt the user for a password.
