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

2

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?

Parmesan answered 30/10, 2015 at 5:26 Comment(2)
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?Parrot
In PowerShell 3, SQLPS module was exist in $env:PSModulePath. But after installation of PowerShell 4 it is not exist.Parmesan
K
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
Kab answered 27/3, 2016 at 17:1 Comment(7)
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.Parmesan
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"Kab
It works, but I have to run same each and every time after restarting the power Shell editor. So is it correct behaviour?Parmesan
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\Kab
Great!! I have copied SQLPS module at power shell module at C:\Windows\system32\WindowsPowerShell\v1.0\Modules. It works perfectly..Parmesan
Quick note - the SQLPS module is now deprecated in favor of the SqlServer module which can be installed via Install-Module SqlServer. See learn.microsoft.com/en-us/sql/powershell/… for reference.Domeniga
@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.Kab
D
-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
Declared answered 6/12, 2018 at 5:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.