- 1 year ago
Pass a password & username without prompting in Powershell to open an application
Comment
1 / 1
In PowerShell, you can use the Start-Process
cmdlet to launch an application and provide the username and password programmatically without prompting the user. Here's an example:
powershell$username = "your_username"
$password = "your_password" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Start-Process -FilePath "C:\Path\To\Application.exe" -Credential $credential
In this example:
- Set the
$username
variable to the desired username. - Set the
$password
variable to the corresponding password. - The password is converted to a secure string using the
ConvertTo-SecureString
cmdlet. - Create a
PSCredential
object using the username and secure password. - Use the
Start-Process
cmdlet to launch the application (Application.exe
in this example) and pass the$credential
object as the-Credential
parameter.
This approach allows you to provide the username and password directly in the script without prompting the user. However, note that storing sensitive information like passwords in clear text in a script is not recommended for security reasons. Consider using other secure methods, such as storing the credentials in a secure location or prompting the user to enter the credentials at runtime.