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
Copy file name to clipboardExpand all lines: docs/powershell/sql-server-powershell.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,11 @@ description: Learn about the two SQL Server PowerShell modules, SqlServer and SQ
4
4
author: markingmyname
5
5
ms.author: maghan
6
6
ms.reviewer: matteot
7
-
ms.date: 06/11/2020
7
+
ms.date: 08/07/2023
8
8
ms.service: sql
9
9
ms.subservice: sql-server-powershell
10
10
ms.topic: conceptual
11
+
ms.custom: UpdatedFrequency5
11
12
---
12
13
13
14
# SQL Server PowerShell
@@ -32,7 +33,7 @@ You can also use [PowerShell with Azure Data Studio](../azure-data-studio/extens
32
33
33
34
**Why did the module change from SQLPS to SqlServer?**
34
35
35
-
To ship SQL PowerShell updates, we had to change the identity of the SQL PowerShell module, and the wrapper known as *SQLPS.exe*. Because of this change, there are now two SQL PowerShell modules, the **SqlServer** module, and the **SQLPS** module.
36
+
To ship SQL PowerShell updates, we had to change the identity of the SQL PowerShell module, and the wrapper known as *SQLPS.exe*. Because of this change, there are now two SQL PowerShell modules, the **SqlServer** module, and the **SQLPS** module.
36
37
37
38
**Update your PowerShell scripts if you import the SQLPS module.**
38
39
@@ -48,7 +49,7 @@ The **SqlServer** module comes with:
48
49
49
50
-[PowerShell Providers](/powershell/module/microsoft.powershell.core/about/about_providers), which enables a simple navigation mechanism similar to file system paths. You can build paths similar to file system paths, where the drive is associated with a SQL Server management object model, and the nodes are based on the object model classes. You can then use familiar commands such as **cd** (alias for Set-Location) and **dir** (alias for Get-ChildItem) to navigate the paths similar to the way you navigate folders in a command prompt window. You can use other commands, such as **ren** (alias for Rename-Item) or **del** (alias for Remove-Item), to perform actions on the nodes in the path.
50
51
51
-
- A set of cmdlets that support actions such as running a **sqlcmd** script containing Transact-SQL or XQuery statements.
52
+
- A set of cmdlets that support actions such as running a **sqlcmd** script containing Transact-SQL or XQuery statements.
52
53
53
54
- The AS provider and cmdlets, which before they were installed separately.
54
55
@@ -61,19 +62,20 @@ SQL PowerShell cmdlets can be used to manage instances of Azure SQL Database, Az
61
62
The **Encode-Sqlname** (alias for ConvertTo-EncodedSqlName) and **Decode-Sqlname** (alias for ConvertFrom-EncodedSqlName) cmdlets help you specify SQL Server identifiers that contain characters not supported in PowerShell paths. For more information, see [SQL Server Identifiers in PowerShell](sql-server-identifiers-in-powershell.md).
62
63
63
64
Use the **Convert-UrnToPath** cmdlet to convert a Unique Resource Name for a Database Engine object to a path for the SQL Server PowerShell provider. For more information, see [Convert URNs to SQL Server Provider Paths](/powershell/module/sqlserver/Convert-UrnToPath).
64
-
65
-
## Query Expressions and Uniform Resource Names
65
+
66
+
## Query Expressions and Uniform Resource Names
66
67
67
68
Query expressions are strings that use syntax similar to XPath to specify a set of criteria that enumerates one or more objects in an object model hierarchy. A Uniform Resource Name (URN) is a specific type of query expression string that uniquely identifies a single object. For more information, see [Query Expressions and Uniform Resource Names](query-expressions-and-uniform-resource-names.md).
68
69
69
70
## SQL Server Agent
70
71
71
72
There's no change to the module used by SQL Server Agent. As such, SQL Server Agent jobs, which have PowerShell type job steps use the SQLPS module. For more information, see [How to run PowerShell with SQL Server Agent](run-windows-powershell-steps-in-sql-server-agent.md). However, starting with SQL Server 2019, you can disable SQLPS. To do so, on the first line of a job step of the type PowerShell you can add `#NOSQLPS`, which stops the SQL Agent from auto-loading the SQLPS module. When you do this, your SQL Agent Job runs the version of PowerShell installed on the machine, and then you can use any other PowerShell module you like.
72
73
73
-
### Troubleshooting SQLPS
74
-
If you see agent job steps (PowerShell subsystem) failing with the following error, this section may be helpful in troubleshooting the issue.
74
+
### Troubleshoot SQLPS
75
+
76
+
If you see agent job steps (PowerShell subsystem) failing with the following error, this section may be helpful in troubleshooting the issue.
75
77
76
-
> A job step received an error at line 1 in a PowerShell script. The corresponding line is 'import-module SQLPS'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The specified module 'SQLPS' was not loaded because no valid module file was found in any module directory.
78
+
> A job step received an error at line 1 in a PowerShell script. The corresponding line is 'import-module SQLPS'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The specified module 'SQLPS' was not loaded because no valid module file was found in any module directory.
77
79
78
80
The SQLPS module must be available at the environment variable PSModulePath. Uninstalling SSMS 16.x may remove the SQLPS from PSModulePath. To check the current values stored in PSModulePath, run the following PowerShell:
79
81
@@ -92,8 +94,6 @@ If you want to use the **SqlServer** module in your SQL Agent Job step, you can
0 commit comments