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
* Added SQL PowerShell Examples
Added examples specific to the official SqlServer PowerShell module, to help customers get started.
* Update Code Formatting
Updated the format of the code examples.
* Moved SQL PowerShell Examples
Moved location of SQL PowerShell Examples to be after Example Scripts.
* Typo
Fixed typo in description.
* Commas
Commas.
* Update docs/azure_data_studio/README_FOR_MARKETPLACE.md
Co-Authored-By: SQLvariant <[email protected]>
* Update docs/azure_data_studio/README_FOR_MARKETPLACE.md
Co-Authored-By: SQLvariant <[email protected]>
* Update docs/azure_data_studio/README_FOR_MARKETPLACE.md
Co-Authored-By: SQLvariant <[email protected]>
* Apply suggestions from code review
Co-Authored-By: SQLvariant <[email protected]>
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
+
81
+
```powershell
82
+
Install-Module -Name SqlServer -AllowPrerelease
83
+
```
84
+
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
+
87
+
```powershell
88
+
Get-SqlInstance -ServerInstance ServerA, ServerB
89
+
```
90
+
91
+
Here is a sample of what that output will look like:
92
+
93
+
```
94
+
Instance Name Version ProductLevel UpdateLevel
95
+
------------- ------- ------------ -----------
96
+
ServerA 13.0.5233 SP2 CU4
97
+
ServerB 14.0.3045 RTM CU12
98
+
```
99
+
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
+
102
+
```powershell
103
+
dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
104
+
WHERE { $_.Mode -ne 'd' } |
105
+
FOREACH {
106
+
Get-SqlDatabase -ServerInstance $_.Name
107
+
}
108
+
```
109
+
110
+
Here is a sample of what that output will look like:
AdventureWorks2017 Normal 336.00 MB 57.01 MB Simple 140 sa
117
+
master Normal 6.00 MB 368.00 KB Simple 140 sa
118
+
model Normal 16.00 MB 5.53 MB Full 140 sa
119
+
msdb Normal 48.44 MB 1.70 MB Simple 140 sa
120
+
PBIRS Normal 144.00 MB 55.95 MB Full 140 sa
121
+
PBIRSTempDB Normal 16.00 MB 4.20 MB Simple 140 sa
122
+
SSISDB Normal 325.06 MB 26.21 MB Full 140 sa
123
+
tempdb Normal 72.00 MB 61.25 MB Simple 140 sa
124
+
WideWorldImporters Normal 3.2 GB 2.6 GB Simple 130 sa
125
+
```
126
+
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
+
129
+
```powershell
130
+
Get-SqlDatabase -ServerInstance ServerB |
131
+
Out-GridView -PassThru |
132
+
Backup-SqlDatabase -CompressionOption On
133
+
```
134
+
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
+
137
+
```powershell
138
+
dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
0 commit comments