我正在使用PowerShell,我需要自动启动一次作业转轮 我的脚本运行但是得到了一个例外"由于无法启动服务 登录失败"。
任何人都可以帮助我如何解决该错误?
function ServiceStart($ServiceName){
try
{
Write-Host $("Starting service " + $ServiceName)
$timeout = [System.TimeSpan]::FromMinutes(5)
$arrService = Get-Service -Name $ServiceName
if ($arrService -eq $null)
{
Write-Host $("**ERROR** No service named '" + $ServiceName + "'
found")
return $false
}
if ($arrService.Status -eq
[ServiceProcess.ServiceControllerStatus]::Running)
{
return $true
}
$arrService.Start()
try
{
$arrService.WaitForStatus([ServiceProcess.ServiceControllerStatus]
::Running, $timeout)
}
catch [ServiceProcess.TimeoutException]
{
Write-Verbose "Timeout starting service $($arrService.Name)"
throw "Timeout starting service $($arrService.Name)"
}
Write-Host $("Started service " + $ServiceName)
return $true
}
catch
{
Write-Host $("**ERROR** Unable to start service '$ServiceName'.
Exception: " + $_.Exception.Message + ". InnerException: " +
$_.Exception.InnerException)
throw $("**ERROR** Unable to start service '$ServiceName'. Exception: "
+ $_.Exception.Message + ". InnerException: " +
$_.Exception.InnerException)
}