Invoke-Command with static password

2019-08-26 13:08发布

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 

1条回答
Viruses.
2楼-- · 2019-08-26 13:42

You can add this code block:

$User = "UserName"
$PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force
$Credential = [pscredential]::new($user,$Password)
查看更多
登录 后发表回答