You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to use these examples (below), you need to install the SqlServer module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/SqlServer).
In this example, we use the Get-SqlInstance cmdlet to Get the Server SMO objects for ServerA & ServerB. The default output for this command will include the Instance name, version, Service Pack, & CU Update Level of the instances.
Here is a sample of what that output will look like:
114
+
<pre><code><# Sample Output #>
115
+
Instance Name Version ProductLevel UpdateLevel
116
+
------------- ------- ------------ -----------
117
+
ServerA 13.0.5233 SP2 CU4
118
+
ServerB 14.0.3045 RTM CU12</code></pre>
119
+
120
+
In this example, we will do a 'dir' (alias for Get-ChildItem) to get the list of all SQL Server instances listed in your Registered Servers file, and then use the Get-SqlDatabase cmdlet to get a list of Databases for each of those instances.
121
+
122
+
<pre><code>dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
123
+
WHERE {$_.Mode -ne 'd' } |
124
+
FOREACH {
125
+
Get-SqlDatabase -ServerInstance $_.Name
126
+
}
127
+
</code></pre>
128
+
Here is a sample of what that output will look like:
AdventureWorks2017 Normal 336.00 MB 57.01 MB Simple 140 sa
134
+
master Normal 6.00 MB 368.00 KB Simple 140 sa
135
+
model Normal 16.00 MB 5.53 MB Full 140 sa
136
+
msdb Normal 48.44 MB 1.70 MB Simple 140 sa
137
+
PBIRS Normal 144.00 MB 55.95 MB Full 140 sa
138
+
PBIRSTempDB Normal 16.00 MB 4.20 MB Simple 140 sa
139
+
SSISDB Normal 325.06 MB 26.21 MB Full 140 sa
140
+
tempdb Normal 72.00 MB 61.25 MB Simple 140 sa
141
+
WideWorldImporters Normal 3.2 GB 2.6 GB Simple 130 sa
142
+
</code></pre>
143
+
144
+
This example uses the Get-SqlDatabase cmdlet to retireve a list of all databases on the ServerB instance, then presents a grid/table to select which databases should be backed up. Once the user clicks on the "OK" button, only the highlighted databases will be backed up.
This example again gets list of all SQL Server instances listed in your Registered Servers file, then reports every failed SQL Agent Job since Midnight, for each SQL Server instances listed.
151
+
152
+
<pre><code>dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
0 commit comments