1

Uninstalled the old PS module, downloaded the nuget package for the new 22.2 SqlServer, copied the files over the server which is offline, extracted the files into the modules folder but SQL Server is still referring to the old one rather than the new version. A basic example of Import-Module -Name SqlServer will run successfully when executed in ISE but not as an SQL Agent job step. Error message:

The corresponding line is 'import-module SQLPS -Version 15.0'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The specified module 'SQLPS' with version '15.0' was not loaded because no valid module file was found in any module directory. ' A job step received an error at line 1 in a PowerShell script. The corresponding line is 'SQLSERVER:'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The term 'SQLSERVER:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. '. Process Exit Code -1. The step failed.

Modules, paths and versions are as follows:

Modules, paths and versions:

Can someone help me in setting up SQL Server or PS module so that the agent can import the new module successfully?
Thank you

4
  • 1
    Why did you manually copy the files over to the server instead of installing them from PowerShell Gallery? Did you uninstall the older versions of the SQLPS and SqlServer modules from the user profile of the account under which the SQL Agent service executes? If you're on SQL Server 2019 or later, did you try adding #NOSQLPS on the first line of the PowerShell job? Commented May 8, 2024 at 11:47
  • Because the server is offline, has no internet connection. I don't know how to uninstall modules from a specific user? I was thinking whatever there is under modules directories all accounts will have access to those modules. Commented May 8, 2024 at 11:49
  • Vow. Had no idea about #NOSQLPS and it worked. Haven't come across a documentation regarding yet. Thank you. Commented May 8, 2024 at 11:53
  • 1
    #NOSQLPS is mentioned in the documentation at Run Windows PowerShell Steps in SQL Server Agent. Commented May 8, 2024 at 11:53

1 Answer 1

0

As per @AlwaysLearning comments above, adding #NOSQLPS on the first line of the PowerShell job solved the issue. More info: https://learn.microsoft.com/en-us/sql/powershell/run-windows-powershell-steps-in-sql-server-agent

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.