1

I want to execute a script that requires privileges on a remote Windows Server machine , but each time i execute the script a pop-up window appears in order to type the password, so how can I add the password as a static parameter into the command so I can escape typing it each time (the password is fixe and unknown)

Here is the code that I wrote

Param (
$user
)
Invoke-Command -ComputerName 'Server.Admin.6NLG-AD' -FilePath C:\SECnology\Data\Utilities\PS_Block_Internet_Access_GPO.ps1 -ArgumentList $user  -Credential ADMIN\Administrateur 
mklement0
  • 382,024
  • 64
  • 607
  • 775
MKH_Cerbebrus
  • 51
  • 2
  • 10
  • Possible duplicate of [save PSCredential in the file](https://stackoverflow.com/questions/40029235/save-pscredential-in-the-file) – vonPryz Mar 08 '19 at 14:31
  • I dont think its the same thing. – ArcSet Mar 08 '19 at 14:35
  • Thank you for showing me the other topic but it didn't really solve my problem cause I just need to add statically the password to the command without having to type anything while the script being exectuted – MKH_Cerbebrus Mar 08 '19 at 14:37
  • Possible duplicate of [Using PowerShell credentials without being prompted for a password](https://stackoverflow.com/questions/6239647/using-powershell-credentials-without-being-prompted-for-a-password) – Theo Mar 08 '19 at 14:40

1 Answers1

2

You can add this code block:

$User = "UserName"
$Password = ConvertTo-SecureString -String "Password" -AsPlainText -Force
$Credential = [pscredential]::new($User,$Password)
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27