Disclaimer: i still suck at writing scripts please be gentle if this is a dumb question! :)
What i'm doing is pretty simple. I am using a SqlServerCmdletSnapin which gives me the ability to run t-sql queries in powershell 1.0 and return it to either the console or a out-file. I am currently sending it to a .txt file, my code so far is here:
$sqlcheck = Invoke-Sqlcmd -Query "select * from client" -ServerInstance "TESTDB1\TESTSQL1" | out-file -filepath "C:\MyFolder\Client_Result.txt"
The above returns a line of sql (example):
1 CAAT PI 2003-08-05 13:34:00 PI 2003-08-05 13:34:00
So this sends the results to the .txt file. What im trying to accomplish is from the results that print to the .txt file, if it returns nothing or blank, than that's a failure and it should send an e-mail.
I already wrote an e-mail function for this but what i'm stumbling on is how i'm actually going to check for empty results or i guess $null results. I'm probably using the completely wrong logic but, im writing something like this:
$sqlcheck = Invoke-Sqlcmd -Query "select * from client" -ServerInstance "TESTDB1\TESTSQL1" | out-file -filepath "C:\MyFolder\Client_Result.txt"
if($sqlcheck -is [Array]){
if($sqlcheck[1] -match "OK"){
echo "Status is OK" > C:\MyFolder\Result.log
}
}
else{
Send-Email
}
Obviously not working! Someone please slap me with some knowledge. :)
Thanks!