Powershell script enhancement

  • Hi everyone.

    I have a script that works great at the moment.

    The Script I use checks all SQL servers in a table for the last backup status. It then emails out an exception report for databases missing a full backup etc.

    As I mentioned script works fine for all databases on the instances being checked.

    The enhancement I want to do is to amend the script to ignore certain databases that exist in say an exception table.

    This is the code segment that I think I need to amend.

    # COMMENT: This script checks every server in the inventory, and gets the databases

    #that have not been backed up for some time defined by minutes.

    # An exception report is created and sent to the DBA group.

    # Loop through the list OF SQL Server instances AND run the CHECK-Backups FUNCTION

    # against each instance TO get the BACKUP exceptions.

    Foreach ($sqlServer IN $sqlServers) {

    $sqlNetworkName=$sqlServer.SQLNetworkName

    $sqlInstanceName=$sqlServer.instanceName

    $tcpPort=$sqlServer.tcpPort

    $strResult=""

    IF ($sqlInstanceName -ieq 'MSSQLSERVER') {

    $strResult=(CHECK-Backups "$sqlNetworkName,$tcpPort"$backupType $minutes)

    IF ($strResult -ne "" {

    $exceptions=$exceptions + $strResult + "`n" }

    }

    ELSE {

    $strResult=(CHECK-Backups "$sqlNetworkName\$sqlInstanceName,$tcpPort"$backupType $minutes)

    IF ($strResult -ne "" {

    $exceptions=$exceptions + $strResult + "`n" }

    }

    }

    I am guessing I need some kind of table created that holds the databases to be excluded. The Script will then run against all the database in inventory , but then exclude those databases it finds in the exception table.

    Just not sure on how to code that ??

    Any help or advice appreciated,

  • Something like this?

    foreach ($CurrentlyProcessingDB in $MyListOfDBs)

    {

    if ($ListOfDbsToIgnore -notcontains $CurrentlyProcessingDB)

    {

    Do stuff

    }

    }

Viewing 2 posts - 1 through 1 (of 1 total)

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