'If not run after get-service in powershell

I'm trying to access the service status of the remote server. i wrote this

$ServerList = get-content -Path "c:\users\cont015\Desktop\ServerList.txt"
ForEach ($ServerName in $ServerList) 
{
  $Status= Get-Service -ComputerName $ServerName | ?{$_.DisplayName -like "SQL Server (*"} |        select Status | format-wide
  if($st -eq "Running")
  { 
    $SeverName
    $Status
  }
  else
  {
  }
}

it is showing

$Status= Get-Service -ComputerName $ServerName | ?{$_.DisplayName -li ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Service], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

in error. i don't know what i am missing. but when i run without if condition if shows proper output.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source