Skip to content

Commit 2056b74

Browse files
committed
improvement via matteo
1 parent 2e97efa commit 2056b74

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

docs/powershell/sql-server-powershell.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,20 @@ 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:
75+
### Troubleshooting SQLPS
76+
If you see agent job steps (PowerShell subsystem) failing with the following error, this section could be relevant/good troubleshooting.
77+
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.
79+
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:
7681

7782
```powershell
7883
$env:PSModulePath -split ";"
7984
```
8085

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*.
86+
If the path is set, you will see an entry similar to `C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules`. If the path is not set, locate the SQLPS folder on your server and add it to the environment variable value either through PowerShell or in *System Properties>Advanced>Environment Variables*.
87+
88+
### SQLServer module with SQL Agent
8289

8390
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.
8491

0 commit comments

Comments
 (0)