Good Afternoon from the Midwest,
I am having a problem getting the output from my script to act the way that i want it to.
Here is the script:
$ErrorActionPreference = "silentlycontinue";
$service = Get-Service -name MSSQL$*, MSSQLSERVER*, SQLAGENT$*, ReportWriter$*, SQLSERVERAGENT -Exclude ReportWriter$CRM_DEV, ReportWriter$CRM_DEV02, MSSQLServerOLAPService, MSSQLServerADHelper100 | Select-Object DisplayName
$status = Get-Service -name MSSQL$*, MSSQLSERVER*, SQLAGENT$*, ReportWriter$*, SQLSERVERAGENT -Exclude ReportWriter$CRM_DEV, ReportWriter$CRM_DEV02, MSSQLServerOLAPService, MSSQLServerADHelper100 | Select-Object Status
$Error.Clear();
if ( ($service -eq "SQL SERVER") -and $status -eq "Running" )
{
Write-Host "Message: $Service in this $status";
exit 0;
}
if ( ($service -eq "SQL SERVER") -and $status -ne "Running" )
{
Write-Host "Message: $Service is not Running, please log into the Server to see why. ";
exit 1;
}
if ( ($service -eq "SQL SERVER AGENT") -and $status -eq "Running" )
{
Write-Host "Message: $Service in this $status";
exit 0;
}
if ( ($service -eq "SQL SERVER AGENT") -and $status -ne "Running" )
{
Write-Host "Message: $Service is not Running, please log into the Server to see why.";
exit 1;
}
if ( ($service -eq "SQL Server Reporting Services") -and $status -eq "Running" )
{
Write-Host "Message: $Service in this $status";
exit 0;
}
if ( ($service -eq "SQL Server Reporting Services") -and $status -ne "Running" )
{
Write-Host "Message: $Service is not Running, please log into the Server to see why.";
exit 1;
}
if ($Error.Count -eq 0) {
Write-Host "Message: All Services are running correctly.";
exit 0;
}
Write-Host "Message: $($Error[0])";
exit 1;
What i am trying to figure out is twofold. One, can you only return numbers or statistics and not Statuses like Running Stopped etc, and if you can return Statuses then how do I format it to get the data i need in the Get Script Output section of the Custom Powershell Monitor.
The variables have the powershell i used get the services i was looking for on a VM and it worked beautifully.