Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Powershell script enhancement Expand / Collapse
Author
Message
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: Thursday, April 10, 2014 2:30 AM
Points: 217, Visits: 1,078
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,
Post #1505157
Posted Thursday, October 17, 2013 10:06 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 6:36 AM
Points: 402, Visits: 859
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