Skip to content

Latest commit

 

History

History
207 lines (154 loc) · 9.7 KB

README_FOR_MARKETPLACE.md

File metadata and controls

207 lines (154 loc) · 9.7 KB

PowerShell Language Support for Azure Data Studio

Build Status Version Installs Discord Join the chat at https://gitter.im/PowerShell/vscode-powershell

This extension provides rich PowerShell language support for Azure Data Studio (ADS). Now you can write and run PowerShell scripts using the excellent IDE-like interface that Azure Data Studio provides.

This extension is powered by the PowerShell language server, PowerShell Editor Services. This leverages the Language Server Protocol where PowerShellEditorServices is the server and vscode-powershell is the client.

Also included in this extension is the PowerShell ISE theme for Visual Studio Code. It is not activated by default, but after installing this extension either click "Set Color Theme" or use the theme picker and select "PowerShell ISE" for a fun and familiar experience.

Platform Support

The extension should work anywhere ADS itself and PowerShell Core 7 or higher is supported. For Windows PowerShell, only version 5.1 is supported. Please note that PowerShell Core 6 is end-of-life and so not supported. Our test matrix includes the following:

  • Windows Server 2019 with Windows PowerShell 5.1 and PowerShell Core 7.2.4
  • macOS 10.15 with PowerShell Core 7.2.5
  • Ubuntu 20.04 with PowerShell Core 7.2.4

Read the installation instructions to get more details on how to use the extension on these platforms.

Read the troubleshooting guide for answers to common questions.

Features

  • Syntax highlighting
  • Code snippets
  • IntelliSense for cmdlets and more
  • Rule-based analysis provided by PowerShell Script Analyzer
  • Go to Definition of cmdlets and variables
  • Find References of cmdlets and variables
  • Document and workspace symbol discovery
  • Run selected selection of PowerShell code using F8
  • Launch online help for the symbol under the cursor using Ctrl+F1
  • Local script debugging
  • Integrated console support
  • PowerShell ISE color theme

Installing the Extension

You can install the official release of the PowerShell extension by following the steps in the Azure Data Studio documentation. In the Extensions pane, search for "PowerShell" extension and install it there. You will get notified automatically about any future extension updates!

You can also install a VSIX package from our releases page by following the Install from a VSIX instructions. The easiest way is through the command line:

azuredatastudio --install-extension powershell-<version>.vsix

Reporting Problems

If you experience any problems with the PowerShell Extension, see the troubleshooting docs for information on diagnosing and reporting issues.

Security Note

For any security issues, please see here.

Example Scripts

There are some example scripts in the extension's examples folder that you can use to discover PowerShell editing and debugging functionality. Please check out the included README.md file to learn more about how to use them.

This folder can be found at the following path:

$HOME/.azuredatastudio/extensions/ms-vscode.powershell-<version>/examples

To open/view the extension's examples in Azure Data Studio, run the following from your PowerShell session:

azuredatastudio (Get-ChildItem $HOME/.azuredatastudio/extensions/ms-vscode.powershell-*/examples)[-1]

SQL PowerShell Examples

In order to use these examples (below), you need to install the SqlServer module from the PowerShell Gallery.

Install-Module -Name SqlServer

NOTE: With version 21.1.18102 and up, the SqlServer module supports PowerShell Core 6.2 and up, in addion to Windows PowerShell.

In this example, we use the Get-SqlInstance cmdlet to Get the Server SMO objects for ServerA and ServerB. The default output for this command will include the Instance name, version, Service Pack, and CU Update Level of the instances.

Get-SqlInstance -ServerInstance ServerA, ServerB

Here is a sample of what that output will look like:

Instance Name             Version    ProductLevel UpdateLevel  HostPlatform HostDistribution
-------------             -------    ------------ -----------  ------------ ----------------
ServerA                   13.0.5233  SP2          CU4          Windows      Windows Server 2016 Datacenter
ServerB                   14.0.3045  RTM          CU12         Linux        Ubuntu

In the following 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.

dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
WHERE { $_.Mode -ne 'd' } |
FOREACH {
    Get-SqlDatabase -ServerInstance $_.Name
}

Here is a sample of what that output will look like:

Name                 Status           Size     Space  Recovery Compat. Owner
                                            Available  Model     Level
----                 ------           ---- ---------- -------- ------- -----
AdventureWorks2017   Normal      336.00 MB   57.01 MB Simple       140 sa
main               Normal        6.00 MB  368.00 KB Simple       140 sa
model                Normal       16.00 MB    5.53 MB Full         140 sa
msdb                 Normal       48.44 MB    1.70 MB Simple       140 sa
PBIRS                Normal      144.00 MB   55.95 MB Full         140 sa
PBIRSTempDB          Normal       16.00 MB    4.20 MB Simple       140 sa
SSISDB               Normal      325.06 MB   26.21 MB Full         140 sa
tempdb               Normal       72.00 MB   61.25 MB Simple       140 sa
WideWorldImporters   Normal         3.2 GB     2.6 GB Simple       130 sa

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.

Get-SqlDatabase -ServerInstance ServerB |
Out-GridView -PassThru |
Backup-SqlDatabase -CompressionOption On

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.

dir 'SQLSERVER:\SQLRegistration\Database Engine Server Group' -Recurse |
WHERE {$_.Mode -ne 'd' } |
FOREACH {
    Get-SqlAgentJobHistory -ServerInstance  $_.Name -Since Midnight -OutcomesType Failed
}

Contributing to the Code

Check out the development documentation for more details on how to contribute to this extension!

Maintainers

Emeriti

License

This extension is licensed under the MIT License. Please see the third-party notices file for details on the third-party binaries that we include with releases of this project.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.