Skip to content

Commit 162701e

Browse files
committed
Added SQL PowerShell Examples
Added examples specific to the official SqlServer PowerShell module, to help customers get started.
1 parent d170c9b commit 162701e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/azure_data_studio/README_FOR_MARKETPLACE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,56 @@ For more information see the [Code of Conduct FAQ][conduct-FAQ] or contact [open
101101
[conduct-FAQ]: http://opensource.microsoft.com/codeofconduct/faq/
102102
[conduct-email]: mailto:[email protected]
103103
[conduct-md]: https://github.com/PowerShell/vscode-powershell/blob/master/CODE_OF_CONDUCT.md
104+
105+
## SQL PowerShell Examples
106+
In order to use these examples (below), you need to install the SqlServer module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/SqlServer).
107+
108+
<pre><code>Install-Module -Name SqlServer -AllowPrerelease</code></pre>
109+
110+
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.
111+
112+
<pre><code>Get-SqlInstance -ServerInstance ServerA, ServerB</code></pre>
113+
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:
129+
<pre><code>
130+
Name Status Size Space Recovery Compat. Owner
131+
Available Model Level
132+
---- ------ ---- ---------- -------- ------- -----
133+
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.
145+
146+
<pre><code>Get-SqlDatabase -ServerInstance ServerB |
147+
Out-GridView -PassThru |
148+
Backup-SqlDatabase -CompressionOption On</code></pre>
149+
150+
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 |
153+
WHERE {$_.Mode -ne 'd' } |
154+
FOREACH {
155+
Get-SqlAgentJobHistory -ServerInstance $_.Name -Since Midnight -OutcomesType Failed
156+
}</code></pre>

0 commit comments

Comments
 (0)