i have created a function like below:
function Get-SQLServices
{
Param
(
# Param1 help description
[string[]]$ComputerName = $env:COMPUTERNAME
)
Get-Service -ComputerName $ComputerName | where {$_.name -like '*MSOLAP*' -or
$_.name -like '*MSSQL*' -or
$_.name -like '*SQLAgent*' -or
$_.name -like '*ReportServer*' -or
$_.name -like '*SQLBrowser*' -or
$_.name -like '*SQLPBENGINE*' -or
$_.name -like '*SQLPBDMS*' -or
$_.name -like '*MsDtsServer*' -or
$_.name -like '*MSSQLLaunchpad*' -or
$_.name -like '*SQLSERVERAGENT*' -and
$_.name -notlike '*MSSQLFDLauncher*'
} | Select status, Name, DisplayName, MachineName ,DependentServices,ServicesDependedOn
}
and when i try to use below command i get error although the service exists:
Get-SQLServices -ComputerName myserver| where {$_.name -eq ‘MSOLAP$DVLP2014’} |Restart-Service
Error:
Restart-Service : Cannot find any service with service name ‘MSOLAP$DVLP2014’.
At line:1 char:86
- … AP$DVLP2014’} |Restart-Service
-
~~~~~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (MSOLAP$DVLP2014:String) [Restart-Service], ServiceCommandException
- FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.RestartServiceCommand