I have some SQL Server machines that cannot connect to any external sites.
I have been using PowerShell more and more when managing databases, so I definitely need this module to be installed so that I can use my PowerShell routines.
It has been proven difficult to install the SQL Server module on those offline machines.
When I try to install the module:
the SqlServer
module asks for the NuGet module package:
I then get this ocean of red letters and the following error message as you can see on the picture below:
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection. PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'.
It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet1円.0.0.1\PSModule.psm1:7415 char:30 + ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
What is the workaround for this PowerShell module installation?
3 Answers 3
PowerShell has a built-in mechanism for this which should be easier than the previous answer.
From an Internet-connected computer, run Save-Module sqlserver -path c:\tmp
(substitute whatever path you want for the module to be saved to). This will save the module to a directory of the same name in c:\tmp
(c:\tmp\SqlServer
).
Then, copy that whole directory to your target computer(s). You have a couple options for the destination, depending upon how you want to make it available to users. On PowerShell 5.1 and older look at the paths in the PSModulePath
environment variable. On my system, I have:
> $env:psmodulepath.split(";")
C:\Users\MYNAME\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Intel\Wired Networking\
C:\Program Files (x86)\Microsoft SQL Server150円\Tools\PowerShell\Modules\
To make the module available to all users, I'd put it in C:\Program Files\WindowsPowerShell\Modules
. For just myself, it'll go into C:\Users\MYNAME\Documents\WindowsPowerShell\Modules
These paths may be a bit different if you're running PowerShell Core or PowerShell 7; you'd look at one or more of the paths in $PSGetPath
.
From here, you should be able to run Import-Module sqlserver
successfully.
Shameless plug: If you're doing a lot of SQL Server administration via PowerShell (and I heartily encourage it!), you should be checking out the dbatools
module.
-
1this is amazing, nice to meet you
Save-Module
, +1 thanks for posting, I had to go through that rough path to get it done, this is way easier, I am glad I posted!!!Marcello Miorelli– Marcello Miorelli2020年04月14日 17:08:31 +00:00Commented Apr 14, 2020 at 17:08 -
ah but I am not sure about the Nuget thing, anyway that is dealt with in the other answerMarcello Miorelli– Marcello Miorelli2020年04月14日 17:11:17 +00:00Commented Apr 14, 2020 at 17:11
-
1Nuget shouldn't be needed with the
save-module
approach.alroc– alroc2020年04月14日 17:53:50 +00:00Commented Apr 14, 2020 at 17:53 -
I have installed per this but when I do sqlcmd -? nothing comes up. Does it have to be SQL standard or higher?JukEboX– JukEboX2021年08月09日 11:53:07 +00:00Commented Aug 9, 2021 at 11:53
This is the way I got it done. I got the information from several articles online, like this, and this.
I am very thankful for the people who made those articles available.
So looking on another computer (that does have Internet access) ensure that the NuGet package is installed and explore that folder. We can see:
So if we copy that DLL file over to the machine without Internet access, and store it in the same folder structure, just make sure you close and reopen you PowerShell ISE program.
If now you try the install-module -name sqlserver
again, you will still get a message about a repository needed:
And then the error message below:
So you better manually download the SqlServer
module package currently from here.
To download manually, click on Download the raw nupkg file. A copy of the package is copied to the download folder for your browser with the name ..nupkg.
There are some instructions here:
- Download module on a system that has access to Internet from here
- This will download a folder in .nupkg format. Rename the folder to .zip extension.
- Copy the zip folder to any location on the target server (in my case
c:\sql_install
and unzip it into a folder - rename the folder tosqlserver
go to PowerShell and run the following script:
$env:PSModulePath
from the above result you can see my path, and based on that I copied the
sqlserver
folder - from2
to the following locations:C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
C:\Program Files> (x86)\Microsoft SQL Server130円\Tools\PowerShell\Modules\
Close and reopen powershell ise (always as administrator)
Check in the powershell ise -> Modules - if
sqlserver
is there:If it is not - then something went wrong - otherwise you should be able now to run
Import-Module sqlserver
And as I test in PowerShell:
Get-SqlAgent -ServerInstance my_server_name
If it worked fine, you're good to go.
The TLS settings need to be updated.
Run Powershell as Administrator and run the following commands prior to installing the SQLServer Module.
a.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
b.
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
Once installed, you may now install the SLQServer Module.
Install-Module -Name SqlServer
The module should now install.
-
That worked for me, thank you so much @mustaccio and @neil-bunderson! On a machine running PS v5.1.19041.1682 / Windows v10.0.19042 N/A Build 19042. It looks like the solution is highly dependent on the actual OS & PS version...idrositis– idrositis2022年08月16日 10:44:41 +00:00Commented Aug 16, 2022 at 10:44
Explore related questions
See similar questions with these tags.