PowerShell 4 - Import-Module : The specified module 'SQLPS' was not loaded because no valid module file was found in any module directory

56,059

Sounds like you need to manually update the module path.

Check to see that this directory exists on the computer.

C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS

[Fixed]

If it does then run

$env:PSModulePath = $env:PSModulePath + ";C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules"

Then check to see if the SQLPS module is in the list of available modules using

get-module -listavailable
Share:
56,059
Yogesh Patel
Author by

Yogesh Patel

I am s\w engineer.

Updated on July 18, 2022

Comments

  • Yogesh Patel
    Yogesh Patel almost 2 years

    Previously working with PowerShell 3. Upgraded to PowerShell 4 and uninstalled it as facing error stated. Import-Module : The specified module 'SQLPS' was not loaded because no valid module file was found in any module directory. But all SQL related stuff is working fine without the error. What is the root cause of this error in PowerShell console?

  • Yogesh Patel
    Yogesh Patel about 8 years
    I have run "$env:PSModulePath = $env:PSModulePath + ";C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS" as directory exist. And then execute get-module -listavailable, SQLPS is available, but still facing same error. And if I restart power Shell editor SQLPS is not listing in get-module -listavailable.
  • RiverHeart
    RiverHeart about 8 years
    Try dropping the SQLPS portion when you add the path to psmodulepath $env:PSModulePath = $env:PSModulePath + ";C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules"
  • Yogesh Patel
    Yogesh Patel about 8 years
    It works, but I have to run same each and every time after restarting the power Shell editor. So is it correct behaviour?
  • RiverHeart
    RiverHeart about 8 years
    Yes, it is normal behavior. The environment variable will reset every time you open powershell. You can either run "sysdm.cpl" --> Advanced --> Environment Variables and modify the PSModulePath path there or you can try copying the SQLPS module to the system path for power shell modules at C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
  • Yogesh Patel
    Yogesh Patel about 8 years
    Great!! I have copied SQLPS module at power shell module at C:\Windows\system32\WindowsPowerShell\v1.0\Modules. It works perfectly..
  • David Mohundro
    David Mohundro almost 6 years
    Quick note - the SQLPS module is now deprecated in favor of the SqlServer module which can be installed via Install-Module SqlServer. See docs.microsoft.com/en-us/sql/powershell/… for reference.
  • RiverHeart
    RiverHeart almost 6 years
    @DavidMohundro Good to know. That module does appear to require Powershell v5, so if you are on Server 2016 or higher you should be good to go otherwise you'll need to update your Powershell install to use it.