When my PowerShell script runs, it prompts the user for a password parameter. That password can contain any number of special characters like *\~;(%?.:@/ That password is then used as a parameter for a .exe command, but it is often incorrect due to some special characters not being escaped properly.
An example past password was $(?-.?-(. The only characters I needed to escape was '(', which I replaced with '`(' to make it work. However, that password is now expired. The new password is something like *\~;~(%?.:@/ *NOTE: these passwords have random numbers and letters mixed into them as well, but have been redacted.
The only characters in the new password NOT in the first are *\~;%:@/ Is there an easy way to escape all characters and just take any user input as it is? If not, would someone mind helping me escape these special characters?
param (
[Parameter(Mandatory=$true)][string]$password
)
The above code prefaces the script, causing the console to prompt for user input.
Invoke-Expression -Command "<path_to_exe> -install $user $password"
^this is the command that uses that password parameter
I have tried many other suggestions on Stack Overflow, Reddit, and other various coding forums/blogs and none have worked. Any help is much appreciated!
Invoke-Expression
.& 'C:\path\to\your.exe' -install $user $password
will do what you want. – Carabin