forked from dataplat/dbatools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type-extensions.ps1
45 lines (34 loc) · 1.47 KB
/
type-extensions.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
# Only update on first import
if (-not ([Sqlcollaborative.Dbatools.dbaSystem.SystemHost]::ModuleImported)) {
# Implement query accelerator for the server object
Update-TypeData -TypeName Microsoft.SqlServer.Management.Smo.Server -MemberName Query -MemberType ScriptMethod -Value {
param (
$Query,
$Database = "master",
$AllTables = $false
)
if ($AllTables) { ($this.Databases[$Database].ExecuteWithResults($Query)).Tables }
else { ($this.Databases[$Database].ExecuteWithResults($Query)).Tables[0] }
} -ErrorAction Ignore
Update-TypeData -TypeName Microsoft.SqlServer.Management.Smo.Server -MemberName Invoke -MemberType ScriptMethod -Value {
param (
$Command,
$Database = "master"
)
$this.Databases[$Database].ExecuteNonQuery($Command)
} -ErrorAction Ignore
Update-TypeData -TypeName Microsoft.SqlServer.Management.Smo.Database -MemberName Query -MemberType ScriptMethod -Value {
param (
$Query,
$AllTables = $false
)
if ($AllTables) { ($this.ExecuteWithResults($Query)).Tables }
else { ($this.ExecuteWithResults($Query)).Tables[0] }
} -ErrorAction Ignore
Update-TypeData -TypeName Microsoft.SqlServer.Management.Smo.Database -MemberName Invoke -MemberType ScriptMethod -Value {
param (
$Command
)
$this.ExecuteNonQuery($Command)
} -ErrorAction Ignore
}