我真的很难让它发挥作用。希望有人可以帮助我!
我目前正在为一项服务编写 Powershell 部署脚本。安装服务后,我想将服务恢复选项设置为每次服务在 0 分钟后崩溃时“重新启动服务”。
有谁知道如何使用 Powershell 为远程计算机设置这些选项?
您可以使用 sc.exe 编写 powershell 函数,如下所述here http://www.ehloworld.com/662。该函数看起来像:
function Set-Recovery{
param
(
[string]
[Parameter(Mandatory=$true)]
$ServiceName,
[string]
[Parameter(Mandatory=$true)]
$Server
)
sc.exe "\\$Server" failure $ServiceName reset= 0 actions= restart/0 #Restart after 0 ms
}
您可以像这样调用该函数:
Set-Recovery -ServiceName "ServiceName" -Server "ServerName"
注意:运行脚本的帐户必须具有远程服务器的管理员权限。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)