Automating Daily Checks with Powershell

  • NJ-DBA

    SSChampion

    Points: 13768

    Comments posted to this topic are about the item Automating Daily Checks with Powershell

  • Barry G Freeman

    SSC Eights!

    Points: 860

    I've set this up as I'm looking to create a full-on daily server checks checks myself, so this was very timely.

    I'm getting an error though:

    You must provide a value expression on the right-hand side of the '-' operator.

    At C:\SQLChecks\htmlreports.ps1:427 char:18

    + "Backup Status" - <<<< Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    + CategoryInfo : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : ExpectedValueExpression

    The line at the location is:

    "Backup Status" -Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    As I don't know anything about the inner working of PowerShell yet, Help?

    DBA (Dogsbody with Bad Attitude)

  • Barry G Freeman

    SSC Eights!

    Points: 860

    Ahh, never mind. We're on SQL 2005 so this won't work anyway.

    Back to roll-my-own, then...

    DBA (Dogsbody with Bad Attitude)

  • Ness

    SSCarpal Tunnel

    Points: 4282

    You could add the date parameters into the Xp_readerrorlog stmt if you wish to limit the initial result set?

    SQL DBA
    Every day is a school day, and don't trust anyone who tells you any different.
    http://sqlblogness.blogspot.co.uk

  • richard.bothma

    Grasshopper

    Points: 23

    Hi,

    I am also struggling with the same issue that was mentioned above, when I try execute the powershell script, on the line:

    "Backup Status" -Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    The error message is:

    You must provide a value expression on the right-hand side of the '-' operator.

    At C:\Data\Powershell\HTMLReports\working\htmlreports.ps1:427 char:18

    + "Backup Status" - <<<< Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : ExpectedValueExpression

    I dont have much experience with Powershell so Im not sure what the problem is,

    does anyone know what the problem could be?

    Forgive me if I am missing something silly,

    Thanks

    Richard

  • NJ-DBA

    SSChampion

    Points: 13768

    richard.bothma (12/19/2011)


    Hi,

    I am also struggling with the same issue that was mentioned above, when I try execute the powershell script, on the line:

    "Backup Status" -Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    The error message is:

    You must provide a value expression on the right-hand side of the '-' operator.

    At C:\Data\Powershell\HTMLReports\working\htmlreports.ps1:427 char:18

    + "Backup Status" - <<<< Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : ExpectedValueExpression

    I dont have much experience with Powershell so Im not sure what the problem is,

    does anyone know what the problem could be?

    Forgive me if I am missing something silly,

    Thanks

    Richard

    Not sure why uou are getting that error- and not in front of a machine right now so i cant try to reproduce, but that line is just a header row. I think you should be able to just comment it out.

  • NJ-DBA

    SSChampion

    Points: 13768

    NJ-DBA (12/19/2011)


    richard.bothma (12/19/2011)


    Hi,

    I am also struggling with the same issue that was mentioned above, when I try execute the powershell script, on the line:

    "Backup Status" -Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    The error message is:

    You must provide a value expression on the right-hand side of the '-' operator.

    At C:\Data\Powershell\HTMLReports\working\htmlreports.ps1:427 char:18

    + "Backup Status" - <<<< Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : ExpectedValueExpression

    I dont have much experience with Powershell so Im not sure what the problem is,

    does anyone know what the problem could be?

    Forgive me if I am missing something silly,

    Thanks

    Richard

    Not sure why uou are getting that error- and not in front of a machine right now so i cant try to reproduce, but that line is just a header row. I think you should be able to just comment it out.

    After a second look, there should not be a <<< in the code. Look at the script again. Is this an artifact of your copy/paste? The code should just have -head ... Remove those symbols and any space... Sorry typing from my phone

  • Barry G Freeman

    SSC Eights!

    Points: 860

    No, the <<< is inserted by the PowerShell parser to show where the error is in the line.

    Personally, I think that just stating line number is enough to find an error.

    DBA (Dogsbody with Bad Attitude)

  • skron

    Old Hand

    Points: 361

    I too have to prove that I have checked the servers each day. I also have to include any errors in the sql server error log for the past 24 hours. In addition to the sql server error log, I also have to include any errors from the windows event logs for the last 24 hours. Using Powershell has greatly simplified my life and all it took was an investment in learning some things about Powershell.

    Powershell is a great tools for producing html reports and sending these reports out in email.

  • Barry G Freeman

    SSC Eights!

    Points: 860

    HooO! any chance of a copy of your script? We're on 2005, so no sql built-ins are available for our PowerShell.

    Does your script work on 2005 ?

    DBA (Dogsbody with Bad Attitude)

  • skron

    Old Hand

    Points: 361

    I can post the scripts once I replace items that are specific to my company.

  • Barry G Freeman

    SSC Eights!

    Points: 860

    Excellent, many thanks.

    DBA (Dogsbody with Bad Attitude)

  • skron

    Old Hand

    Points: 361

    Attached is a zip file with the scripts that I use.

  • Barry G Freeman

    SSC Eights!

    Points: 860

    Cheers for this.. I'll be working on this over the next few days..this will be a great help

    DBA (Dogsbody with Bad Attitude)

  • wolraad

    Valued Member

    Points: 60

    Barry G Freeman (12/19/2011)


    I've set this up as I'm looking to create a full-on daily server checks checks myself, so this was very timely.

    I'm getting an error though:

    You must provide a value expression on the right-hand side of the '-' operator.

    At C:\SQLChecks\htmlreports.ps1:427 char:18

    + "Backup Status" - <<<< Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    + CategoryInfo : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : ExpectedValueExpression

    The line at the location is:

    "Backup Status" -Head $a -Body "<H2> ERRORSLIST </H2>"|out-file $workingdir\errors.html

    As I don't know anything about the inner working of PowerShell yet, Help?

    Hi Barry, I got the same error message as you. I had a look at the code on the lines above and there seems to be a pattern similar to 2 of the lines (411 and 415 respectively). I added the following line to the beginning of line 427 that seemed to get the PowerShell script running at least

    "$results7 |convertto-html -Title "

    I'm a noob to PowerShell too, so hope that works for you.

    Wolraad

Viewing 15 posts - 1 through 15 (of 48 total)

You must be logged in to reply to this topic. Login to reply