Hello SWers,
I am working on creating a PS component monitor in SAM. I have been reading as many posts as I can to try to reach my end goal, but I am thinking I need to check with the community to see if what I am trying is possible (I think it is). What I am trying to do is this:
I have a SQL query, that I know returns X word if there is an error in the SQL job. I also know this SQL query will return Y phrase if it is successful. What my PS script does is connects to the SQL server and db, runs the query, and outputs the results to a file. I then run some if-then statements on the results to see if anything matches X, or Y. Here is my if-then:
#Setting results text file to variable
$importedTxt = Get-Content -Path "C:\Code\Sql_Results.txt"
#Read output file and do some processing
forEach ($line in $importedTxt)
{
If ($line -Match "X1" -or $line -Match "X2")
{
$errorLines += $line
}
ElseIf ($line -Match "Y1" -or $line -Match "Y2")
{
$successLines += $line
}
}
#Display errors output if count of errors is is greater than or equal to 1
If ($errorLines.count -ge 1)
{
Write-Host "Statistic.Error: $($errorLines.count)"
Write-Host "Message.Error: $errorLines, please look into the error."
} Else
{
Write-Host "Statistic.Success: $($successLines.count)"
Write-Host "Message.Success: $successLines, process finished with no errors."
}
Now, I am trying to push this into SAM, but it isn't working quite right. I get the following when I try to test my script:
First, is it possible to include BOTH (Statistic.Success / Message.Success) AND (Statistic.Error / Message.Error) in the same script?
Secondly, what credential should I be using to test? The credential I am using here is the same credential I use to log into the Orion server, so I am thinking there is a connection issue going on with this script.
Thank you,
ZP
Edit: Here are links that I've visited to try to figure this out, note that I am not super script savvy!
The Basics of PowerShell (part 1)
The Basics of PowerShell (part 2)