function Start-SqlAgent([string] $AgentServiceName)
{
$agentService = Get-Service -Name $AgentServiceName
if ($AgentServiceName.Status -eq "Running")
{
Write-Host "$AgentServiceName is running"
return
}
Write-Host "Starting $AgentServiceName..."
# Code that starts the service below here (unrelated to my question)
}
当Sql代理服务运行时,我调用如下函数:
Write-Host "Checking SQL Agent service status..."
Start-SqlAgent -AgentServiceName "SQLSERVERAGENT"