{"id":48,"date":"2013-11-05T00:00:00","date_gmt":"2013-01-01T00:00:00","guid":{"rendered":"https:\/\/www.sqlhammer.com\/blog\/t-sql-command-line-options-part-5-sqlps"},"modified":"2026-03-18T21:50:36","modified_gmt":"2026-03-18T21:50:36","slug":"t-sql-command-line-options-part-5-sqlps","status":"publish","type":"post","link":"https:\/\/sqlhammer.com\/index.php\/2013\/11\/05\/t-sql-command-line-options-part-5-sqlps\/","title":{"rendered":"T-SQL Command Line Options &#8211; Part 5 &#8211; SQLPS"},"content":{"rendered":"<h2>SQLPS.exe and SQLPS the module<\/h2>\n<p>SQLPS, like SQLPSX, is a set of extensions to Powershell for interacting with SQL Server. SQLPS first appeared with SQL Server 2008 in the form of a mini-console called SQLPS.exe. This mini-console was based on\u00a0Powershell V1.0 and did not change with the newer version, 2008 R2. Recently released in SQL Server 2012, came SQLPS the module. Powershell V2.0 and above supports modules which is an entirely new way of packaging a library of functions. While SQLPS.exe is a mini-console with pre-defined cmdlets which cannot be changed, SQLPS enables us to take advantage of the cmdlets from our current version of Powershell in addition to utilizing the SQL Server extension.<\/p>\n<p>In this\u00a0last\u00a0part of the <em>T-SQL Command Line Options<\/em>\u00a0blog series, I will explain how to set up both versions of SQLPS but I will only be analyzing the cmdlets from the newest version, SQLPS the module.<\/p>\n<h2>Running SQLPS.exe<\/h2>\n<p>Executing SQLPS.exe is as easy as any other executable. When it is run; the SQLPS mini-shell will launch. The first option is to make a shortcut to the executable location. The location is displayed below.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sqlps-location.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-location.png\" alt=\"\" \/><\/a><\/p>\n<p>The next option is to simply access it via command prompt or Powershell. In either console you should be able to simply type \u201csqlps\u201d to run the application.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sqlps-console.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-console.png\" alt=\"\" \/><\/a><\/p>\n<p>The navigation of your SQL Server and the execution of queries is very similar to the SQLPS module, see below for those details.<\/p>\n<h2>Establishing a connection with SQLPS the module<\/h2>\n<p>SQLPS the module is included when you install SQL Server 2012. If you don\u2019t have SQL Server 2012 you can create your own SQLPS module by following <a href=\"http:\/\/www.sqlservercentral.com\/blogs\/chadmiller\/\">Chad Miller<\/a>\u2018s article,\u00a0<em><a href=\"http:\/\/www.sqlservercentral.com\/blogs\/chadmiller\/2010\/07\/10\/making-a-sqlps-module\/\">Making A SQLPS Module<\/a>.<\/em><\/p>\n<p>Once installed you must import the module into your active Powershell console window. To do this execute the below script.<\/p>\n<pre><code class=\"language-\">Import-Module SQLPS<\/code><\/pre>\n<p><a href=\"\/wp-content\/uploads\/sqlps-import-module.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-import-module.png\" alt=\"\" \/><\/a><\/p>\n<p>As seen above, you trigger a warning when first importing the SQLPS module. This can be ignored. All it is saying is that the SQLPS module is using non-standard verbs in their cmdlets. If you don\u2019t wish to see this message, helpful if you put the import-module command into a profile file, simply run this script instead.<\/p>\n<pre><code class=\"language-\">Import-Module sqlps -DisableNameChecking<\/code><\/pre>\n<p>You\u2019ll also notice that it will automatically change directory to the SQLSERVER PSDrive which is created by the module. You can use \u2018cd\u2019 to exit and re-enter this location at will.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sqlps-root-directory.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-root-directory.png\" alt=\"\" \/><\/a><\/p>\n<p>Once your new PSDrive is accessed you can navigate through the above listed areas of SQL Server. This module was designed to do far more than simply invoke SQL commands but, unfortunately, many of the SQLPS features are out of scope for this blog series. We will, however, be covering the SQL commands in this next section.<\/p>\n<h2>Query execution with SQLPS the module<\/h2>\n<p>Executing a query or SQL command couldn\u2019t be easier with SQLPS. Below is an example of the Invoke-SqlCmd cmdlet running a query, this can be done from any directory, there is no need to have SQLSERVER:\\ as your working directory.<\/p>\n<pre><code class=\"language-\">Invoke-Sqlcmd -Query \"SELECT name FROM sys.databases;\"\u00a0-ServerInstance localhost\\sql2012<\/code><\/pre>\n<p><a href=\"\/wp-content\/uploads\/sqlps-invoke-sqlcmd-serverinstance.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-invoke-sqlcmd-serverinstance.png\" alt=\"\" \/><\/a><\/p>\n<p>This next example runs the same query but from within the context of your working directory.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sqlps-invoke-sqlcmd.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sqlps-invoke-sqlcmd.png\" alt=\"\" \/><\/a><\/p>\n<h2>Wrap up<\/h2>\n<p>I hope this five part blog series on T-SQL command line options provided you some value. We covered the basic functionality of SQLCMD.exe, Powershell native .NET objects, the open source SQLPSX module, SQLPS.exe the mini-shell, and SQLPS the module. In addition to basic query execution and an overview of features we covered the purpose behind each\u2019s use and recommendations as to when you should choose to use one over the other.<\/p>\n<p>If you have a question you\u2019d like answered or have an idea of a SQL Server topic that you\u2019d like me to discuss please feel free to contact me at <a href=\"mailto:dhammer3407@gmail.com\">dhammer3407@gmail.com<\/a> or on twitter <a href=\"http:\/\/twitter.com\/sqlhammer\">@sqlhammer<\/a>.<\/p>\n<h2>Navigation<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.sqlhammer.com\/blog\/t-sql-command-line-options-part-1\/\">Part 1 \u2013 Introduction<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"http:\/\/www.sqlhammer.com\/blog\/t-sql-command-line-options-part-2-sqlcmd-exe\/\">Part 2 \u2013 SQLCMD.exe using command prompt<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"http:\/\/www.sqlhammer.com\/blog\/t-sql-command-line-options-part-3-ps-w-net\/\">Part 3 \u2013 .NET objects using Powershell<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"http:\/\/www.sqlhammer.com\/blog\/t-sql-command-line-options-part-4-sqlpsx\/\">Part 4 \u2013 SQLPSX using Powershell (SQL Server 2000 and above)<\/a><\/li>\n<\/ul>\n<ul>\n<li>Part 5 \u2013 SQLPS using Powershell (SQL Server 2012 \/ 2014)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>SQLPS.exe and SQLPS the module SQLPS, like SQLPSX, is a set of extensions to Powershell for interacting with SQL Server. SQLPS first appeared with SQL Server 2008 in the form of a mini-console called SQLPS.exe. This mini-console was based on\u00a0Powershell V1.0 and did not change with the newer version, 2008 R2. Recently released in SQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":1,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions\/311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/media\/522"}],"wp:attachment":[{"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlhammer.com\/index.php\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}