Search code examples
powershellinvoke-command

Invoke-Command with static password


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 

Solution

  • You can add this code block:

    $User = "UserName"
    $Password = ConvertTo-SecureString -String "Password" -AsPlainText -Force
    $Credential = [pscredential]::new($User,$Password)