Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBook
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
SQL Server
»
CheckDB-MSSQL-UsingADO
CheckDB-MSSQL-UsingADO
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Access
ADO
Analysis Server
Attributes
Backup
CheckDB
Connect
Connection String
Create database
Create table
CSV
Database
DMO
Job
Port
Service
SMO
SQL
SQL Authentication
SQL Server
stop jobs
Views
Windows Authentication
Wizard
WMI
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 423
File size: 1.8kB
Views: 1,661
Embed
CheckDB-MSSQL-UsingADO
## =====================================================================
## Title
: CheckDB-MSSQL-UsingADO
## Description : Run a DBCC against specified server instance and database
## Author
: Idera
## Date
: 9/1/2008
## Input
: -serverInstance <server\instance>
##
-dbName <database name>
##
-verbose
##
-debug
## Output
:
## Usage
: PS> . CheckDB-MSSQL-UsingADO -serverInstance local -dbName master -v -d
## Notes
: Adapted from Jakob Bindslet script
## Tag
: SQL Server, ADO, CheckDB
## Change log
:
## =====================================================================
param
(
[
string
]
$serverInstance
=
"."
,
[
string
]
$dbName
=
"AdventureWorks"
,
[
switch
]
$verbose
,
[
switch
]
$debug
)
function
main()
{
if
(
$verbose
) {
$VerbosePreference
=
"Continue"
}
if
(
$debug
) {
$DebugPreference
=
"Continue"
}
CheckDB-MSSQL
-UsingADO
$serverInstance
$dbName
}
function
CheckDB-MSSQL
-UsingADO
(
$serverInstance
,
$dbName
)
{
trap
[
Exception
]
{
write-error
$
(
"TRAPPED: "
+
$_
.
Exception.Message
);
continue
;
}
$cn
=
new-object
system.data.SqlClient.SqlConnection
( `
"Data Source=$serverInstance;Integrated Security=SSPI;Initial Catalog=$dbName"
);
$ds
=
new-object
System.Data.DataSet
"dsCheckDB"
$query
=
"DBCC CHECKDB($dbName) WITH TABLERESULTS"
$da
=
new-object
"System.Data.SqlClient.SqlDataAdapter"
(
$query
,
$cn
)
$da
.
Fill
(
$ds
)
$dtCheckDB
=
new-object
"System.Data.DataTable"
"dsCheckDB"
$dtCheckDB
=
$ds
.
Tables
[0]
$dtCheckDB
|
Format-Table
-autosize
`
-property
Error, Level, State, MessageText, `
RepairLevel, Status, DbId, ObjectId, `
IndexId, PartitionId, AllocUnitId, File, `
Page, Slot, RefFile, RefPage, RefSlot, Allocation
}
main
Filed under:
ADO
,
SQL Server
,
CheckDB
Run a DBCC against a specified SQL Server instance and database
Copyright 2011 PowerShell.com. All rights reserved.