Invoke-Command with static password

岁酱吖の 提交于 2019-12-11 15:37:39

问题


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:


You can add this code block:

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


来源:https://stackoverflow.com/questions/55065136/invoke-command-with-static-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!