SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell script enhancement


Powershell script enhancement

Author
Message
MickyD
MickyD
SSC-Addicted
SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)

Group: General Forum Members
Points: 448 Visits: 1499
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,
schleep
schleep
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 1326
Something like this?

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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search