forked from rvrsh3ll/Misc-Powershell-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-OracleCommand.ps1
56 lines (40 loc) · 1.08 KB
/
Invoke-OracleCommand.ps1
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
function Invoke-OracleCommand {
<#
.Synopsis
Invoke a command on an oracle database.
.Description
This script connects to an a oracle database and runs a command.
.Parameter User
The user ID
.Parameter Password
The password
.Parameter Source
Location/IP of Data source
.Parameter Source
Command to run. SELECT user FROM dual
.Example
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True)]
[string]$Path = "C:\Oracle\Oracle.ManagedDataAccess.dll",
[Parameter(Mandatory = $True)]
[string]$User,
[Parameter(Mandatory = $True)]
[string]$Password,
[Parameter(Mandatory = $True)]
[string]$Source,
[Parameter(Mandatory = $True)]
[string]$Command
)
Add-Type -Path "$Path"
$con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection("User Id=$User;Password=$Password;Data Source=$Source")
$cmd=$con.CreateCommand()
$cmd.CommandText="$Command"
$con.Open()
$rdr=$cmd.ExecuteReader()
if ($rdr.Read()) {
$rdr.GetString(0)
}
$con.Close()
}