【发布时间】:2018-02-23 23:56:57
【问题描述】:
我将此函数保存到 StartWindowsService.ps1 文件中。 我确保执行策略是“不受限制的”。我按以下方式运行此文件:
在运行下一行之前,我从服务中停止了“FAService”。这样我的函数就会启动服务。
我在 Powershell 命令提示符处运行了以下行。它不会写入任何内容,也不会启动 FASservice。我真的很傻。
C:\LocationofthisFile\ .\StartWindowsService.ps1 StartWindowsService FAService
我也试过
function StartWindowsService{
Param([string] $ServiceName)
$aService = Get-Service -Name $ServiceName
if ($aService.Status -ne "Running"){
Start-Service $ServiceName
Write-Host "Starting " $ServiceName " service"
" ---------------------- "
" Service is now started"
}
if ($aService.Status -eq "running"){
Write-Host "$ServiceName service is already started"
}
}
谢谢
【问题讨论】:
标签: powershell