My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# **********************************************************
# PRTG Custom EXE Sensor, Powershell Demo Script for ADO Connections
# **********************************************************
# created Nov 2009 for PRTG Network Monitor V7 by Paessler Support Team, www.paessler.com
# This script is Open Source and comes without support and warranty


#************ Set Your Connection String Parameters here ****************
# Check out http://www.connectionstrings.com/ or http://www.w3schools.com/ADO/default.asp for help on ADO

# Sample for Microsoft Access Database
# $myconnectionstring = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = c:\test\sample.mdb"

# Sample for MS SQL Server
# $myconnectionstring = "Provider=SQLOLEDB.1;Password=test;Persist Security Info=True;User ID=test;Initial Catalog=yourname;Data Source=10.1.4.105\SQLEXPRESS"

# Sample for Oracle Database
# $myConnectionString = "Provider=MSDAORA.1;Password=test;User ID=test;Data Source=test;Persist Security Info=True"


#************ Set Your SQL Statement Parameters here ****************
# The script assumes that your database contains the table 'employees' with the field 'salary'.
# According to the Database you may have to adjust the SQL statement.

$mysqlstatement = "select MAX(salary) AS MaxSalary from employees"
$mytablecomumnname = "MaxSalary"


#************ Now let's access the database ****************

$adOpenStatic = 3
$adLockOptimistic = 3

$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset

$objConnection.Open($myconnectionstring)


# *********** Check if connection is open *******************

if($objConnection.state -eq 0){
write-host '0:Could not establish connection'
exit 1
}

$objRecordset.Open($mysqlstatement,$objConnection,$adOpenStatic,$adLockOptimistic)

$objRecordset.MoveFirst()

# *********** Check if there are records *******************

if($objRecordset.EOF -eq $True){
write-host '0:No Data found'
exit 2
}

write-host $objRecordset.Fields.Item($mytablecomumnname).Value,":OK"


$objRecordset.Close()
$objConnection.Close()

Change log

r273 by dpaessler on Nov 26, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r271 by dpaessler on Nov 26, 2009   Diff
Initial version
All revisions of this file

File info

Size: 2178 bytes, 62 lines
Powered by Google Project Hosting