Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 2e97efa

Browse files
committed
adds note about SQLPS and path
1 parent 866a380 commit 2e97efa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

docs/powershell/sql-server-powershell.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ Query expressions are strings that use syntax similar to XPath to specify a set
7272

7373
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.
7474

75+
The SQLPS module must be available at the environment variable PSModulePath. Certain actions, such as uninstalling SSMS 16.x, can remove the SQLPS from PSModulePath. To check the current values stored in PSModulePath, run the following PowerShell:
76+
77+
```powershell
78+
$env:PSModulePath -split ";"
79+
```
80+
81+
If the path is set, you will see an entry similar to `C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules`. If the path is not set, locate the SQL Server PowerShell modules folder on your server and add it to the environment variable value either through PowerShell or in *System Properties>Advanced>Environment Variables*.
82+
7583
If you want to use the **SqlServer** module in your SQL Agent Job step, you can place this code on the first two lines of your script.
7684

7785
```powershell
7886
#NOSQLPS
7987
Import-Module -Name SqlServer
8088
```
8189

90+
91+
8292
## Cmdlet reference
8393

8494
- [SqlServer cmdlets](/powershell/module/sqlserver)

0 commit comments

Comments
 (0)