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\PowerShellGet\1.0.0.1\PSModule.psm1:7415
char:30
+ … tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet …
What is the workaround for this PowerShell module installation?
Best Answer
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 inc:\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:To make the module available to all users, I'd put it in
C:\Program Files\WindowsPowerShell\Modules
. For just myself, it'll go intoC:\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.