SQLPS SQL Powershell module is corrupt. How to fix or reinstall?

Grossnickle, Brenda 40 Reputation points
2023-03-30T17:03:50.54+00:00

Re: SQLPS SQL Powershell module is corrupt. How to fix or reinstall?

First, how is it installed? We have SQL 2016, SSMS 15.0.18330.0. Any ideas on how I can repair it or totally remove every trace of it and then reinstall (i have tried repair of SSMS and SQL and restarted the server).

I get the error either in PS or from SQL Server Agent.

SQL Server Agent

Job Step with Type = Powershell. Single line of script - $ExportID = 1

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: 'Value does not fall within the expected range. '. Process Exit Code -1

PS 5

Import-Module SQLPS -Verbose. Failed when trying to load SQLPS.PS1

Import-Module : Value does not fall within the expected range.
At line:1 char:1
+ Import-Module SQLPS -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], ArgumentException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,928 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,451 Reputation points
    2023-03-31T01:49:55.32+00:00

    Hi @Grossnickle, Brenda,

    To fix a corrupt SQLPS module, you can try the following steps:

    Uninstall the SQL Server PowerShell module using the following command:

    Uninstall-Module -Name SQLPS -Force

    Reinstall the SQL Server PowerShell module using the following command:

    Install-Module -Name SqlServer

    This will install the latest version of the SQL Server PowerShell module.

    Best regards,

    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".