-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path00_Using_Get-SqlInstance.ps1
More file actions
46 lines (32 loc) · 1.25 KB
/
00_Using_Get-SqlInstance.ps1
File metadata and controls
46 lines (32 loc) · 1.25 KB
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
Get-SqlInstance -ServerInstance localhost\SQL2017
DIR 'SQLSERVER:\SQLRegistration\Database Engine Server Group' |
Foreach {
Get-SqlInstance -ServerInstance $_.Name
}
<# Let's check on of the Configuration Options of that instance #>
$SQL2017 = Get-SqlInstance -ServerInstance localhost\sql2017
$SQL2017.Configuration.Properties | sort DisplayName | Format-Table -AutoSize
<# What if we want to check just one property #>
$SQL2017.Configuration.Properties |
WHERE {$_.DisplayName -eq 'max server memory (MB)'}
<# Now let's check that one property on all of our instances: #>
#DIR 'SQLSERVER:\SQLRegistration\Database Engine Server Group' |
#Foreach {
#Get-SqlInstance -ServerInstance $_.Name |
#WHERE {$_.DisplayName -eq 'max server memory (MB)'} |
#Format-Table -AutoSize
#}
$SQL2017.Configuration.Properties |
WHERE {$_.DisplayName -eq 'max server memory (MB)'}
<# Another option for filtering that may be faster for you: #>
($SQL2017.Configuration.Properties).Where({$_.DisplayName -eq 'max server memory (MB)'})
<# Change Database Owner #>
<# This doesn't work because .Owner is ReadOnly. #>
$Databases = Get-SqlDatabase -ServerInstance localhost\SQL2017 |
WHERE {$_.owner -ne 'sa'}
foreach ($db in $Databases)
{
"$($db.owner)";
$db.owner = 'sa';
$db.Alter()
}