Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Powershell script enhancement Expand / Collapse
Posted Wednesday, October 16, 2013 6:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, May 25, 2016 7:49 AM
Points: 244, Visits: 1,397
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) {

IF ($sqlInstanceName -ieq 'MSSQLSERVER') {
$strResult=(CHECK-Backups "$sqlNetworkName,$tcpPort"$backupType $minutes)
IF ($strResult -ne "" {
$exceptions=$exceptions + $strResult + "`n" }
$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,
Post #1505157
Posted Thursday, October 17, 2013 10:06 AM


Group: General Forum Members
Last Login: Thursday, May 12, 2016 5:14 AM
Points: 494, Visits: 1,206
Something like this?

foreach ($CurrentlyProcessingDB in $MyListOfDBs)
if ($ListOfDbsToIgnore -notcontains $CurrentlyProcessingDB)
Do stuff

Post #1505795
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse