14

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?

taurus05
  • 2,491
  • 15
  • 28
Yogesh Patel
  • 818
  • 2
  • 12
  • 26
  • Does this error occur when you run the command interactively or when you have it setup a scheduled task or something? Have you tried running $env:PSModulePath and checked that the module definitely still exists there? – Nick Oct 30 '15 at 05:46
  • In PowerShell 3, SQLPS module was exist in $env:PSModulePath. But after installation of PowerShell 4 it is not exist. – Yogesh Patel Oct 31 '15 at 04:27

2 Answers2

19

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
RiverHeart
  • 549
  • 6
  • 15
  • 1
    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. – Yogesh Patel Apr 04 '16 at 10:36
  • 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"` – RiverHeart Apr 05 '16 at 01:08
  • It works, but I have to run same each and every time after restarting the power Shell editor. So is it correct behaviour? – Yogesh Patel Apr 12 '16 at 04:36
  • 2
    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\ – RiverHeart Apr 13 '16 at 14:17
  • 1
    Great!! I have copied SQLPS module at power shell module at C:\Windows\system32\WindowsPowerShell\v1.0\Modules. It works perfectly.. – Yogesh Patel Apr 14 '16 at 07:57
  • 6
    Quick note - the `SQLPS` module is now deprecated in favor of the `SqlServer` module which can be installed via `Install-Module SqlServer`. See https://learn.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module?view=sql-server-2017 for reference. – David Mohundro Jul 09 '18 at 14:45
  • @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. – RiverHeart Jul 10 '18 at 01:36
-4

Its just normal Error.

Step: 1 - We have to check the Path[[ C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS]] is available in our machine.

If yes, follow step 2

Step: 2. Just copy the [SQLPS] folder from the above link 

Step: 3. Paste the same in [[C:\Windows\system32\WindowsPowerShell\v1.0\Modules\\\

Step: 4 Its been occur due to unavailability of the SQLPS
Sanu0786
  • 571
  • 10
  • 15