The script provided demonstrates how to execute a command or an application using a different account in PowerShell. Here’s the script:

$Username = "Leblogosd\david"
$password = "Motdepasse1"
$pwd      = ConvertTo-SecureString $password -AsPlainText -Force
$cred     = new-object system.Management.Automation.PScredential ($Username,$pwd)

Start-Process "C:\Windows\SysWOW64\cmd.exe" -Credential $cred
  • $Username and $password: These lines define the username and password of the account you want to use.
  • ConvertTo-SecureString: This cmdlet converts plain text into a secure string, ensuring that the password is securely handled within the script.
  • PScredential: This creates a credential object, which is then used to initiate the process with the desired user credentials.
  • Start-Process: This cmdlet starts a new process, in this case, cmd.exe, using the credentials provided.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.