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).
80
80
81
-
```
81
+
```powershell
82
82
Install-Module -Name SqlServer -AllowPrerelease
83
83
```
84
84
85
85
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.
86
86
87
-
```
87
+
```powershell
88
88
Get-SqlInstance -ServerInstance ServerA, ServerB
89
89
```
90
90
@@ -99,12 +99,12 @@ ServerB 14.0.3045 RTM CU12
99
99
100
100
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.
101
101
102
-
```
102
+
```powershell
103
103
dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
104
104
WHERE { $_.Mode -ne 'd' } |
105
105
FOREACH {
106
-
Get-SqlDatabase -ServerInstance $_.Name
107
-
}
106
+
Get-SqlDatabase -ServerInstance $_.Name
107
+
}
108
108
```
109
109
110
110
Here is a sample of what that output will look like:
@@ -126,20 +126,20 @@ WideWorldImporters Normal 3.2 GB 2.6 GB Simple 130 sa
126
126
127
127
This example uses the `Get-SqlDatabase` cmdlet to retrieve a list of all databases on the ServerB instance, then presents a grid/table (using the `Out-GridView` cmdlet) to select which databases should be backed up. Once the user clicks on the "OK" button, only the highlighted databases will be backed up.
128
128
129
-
```
129
+
```powershell
130
130
Get-SqlDatabase -ServerInstance ServerB |
131
131
Out-GridView -PassThru |
132
132
Backup-SqlDatabase -CompressionOption On
133
133
```
134
134
135
135
This example, again, gets list of all SQL Server instances listed in your Registered Servers file, then calls the `Get-SqlAgentJobHistory` which reports every failed SQL Agent Job since Midnight, for each SQL Server instances listed.
136
136
137
-
```
137
+
```powershell
138
138
dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
0 commit comments