6
votes

Well, hello there!

I'm working on a Script to get the Sql Job History and need to use the "SqlServer" Module. It's installed but I can't import it due to the Error Message above. When I got to the Modules Path, the Folder "SqlServer" exists and isn't empty. Don't get the problem here.

Thanks in advance!

1
Have you compared the file it is actually looking for with the files in the folder? Also, check the exact path, make sure there isn't an extra \ in there somewhere, or something like that.user1725145
Yeah, already checked the $env:PSModulePath Variable. Didn't find anything there. Also added the Path a second time to make sure it'll go through this Folder. Doesn't work still. How do I check the file it is looking for? I mean it doesn't say the name of the file on the Error message so how do I know which file powershell is looking for?mbr
Which version of powershell/sql/operating system?G42
PSVersion 5.0.10586.117; Microsoft SQL Server Management Studio 12.0.5571.0; SQL Server 2014; Operating System Server 2012mbr

1 Answers

5
votes

I just ran into this on SQL Server 2017 (on Windows Server 2016) and found your question in the process. I then went and fired up our older SQL Server 2014 (Windows Server 2012) machine and found the same issue. Here's a couple options everyone can try to save some time (as I realize the question is kind of old and I'm assuming the OP found a solution already):

1) At a powershell command run: Install-Module -Name SqlServer (you might need -AllowClobber parameter)

The thing here is that module is installed to the following path on both 2012 and 2016 servers:

C:\Program Files\WindowsPowerShell\Modules\SqlServer (rather than Microsoft SQL Server\120\Tools\PowerShell\Modules)

2) Another option is to try the SQLPS module by changing in your script:

Import-Module -Name SqlServer

To:

Import-Module -Name SQLPS

You will find SQLPS in the Microsoft SQL Server directory structure here:

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

My script works with both SQL modules now, but the output actually looks better with SQLPS at this point...

You can find more on all of the above at this link