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 commentaire

Laisser un commentaire

Emplacement de l’avatar

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.