【发布时间】:2023-03-08 21:30:01
【问题描述】:
当我在服务器名称搅拌 ub vnfqdn.txt 上从本地计算机运行以下脚本时,脚本暂停并要求我输入用户名和凭据。我想以安全的方式在脚本中自动提供密码。你能帮我在下面的脚本中添加任何可以提供帮助的命令吗?
$hostname=get-content C:\temp\vmfqdn.txt
$patchetest=Invoke-Command -ComputerName $hostname -Credential domain\username -ScriptBlock {(Get-HotFix -id "KB4534271").HotFixID}
if($patchetest -eq "KB4534271"){
write-host("Patch KB4534271 is installed")
} else {
write-host("Patch is not installed")
}
'''
how to add credentials in power shell script, so that when i run the script it wont ask for password, I do not want password to be seen in the script.
note- Above script works fine when I provide password manually when window asking for password prompts up.
【问题讨论】:
-
使用您想要的正确用户名从调度程序运行脚本。
-
链接的帖子显示了如何将凭据保存到文件并稍后解密。注意:仅在 Windows 上使用此技术。它仅适用于给定计算机上的给定用户帐户。
标签: powershell credentials powershell-remoting