How can I install the SQL Server PowerShell module on an offline machine?

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 Server\150\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.


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:

Enter image description here

Enter image description here

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:

Enter image description here

And then the error message below:

enter image description here

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:

  1. Download module on a system that has access to Internet from here
  2. This will download a folder in .nupkg format. Rename the folder to .zip extension.
  3. 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 to sqlserver
  4. go to PowerShell and run the following script:

    $env:PSModulePath
    

    Enter image description here

  5. from the above result you can see my path, and based on that I copied the sqlserver folder - from 2 to the following locations:

    C:\Program Files\WindowsPowerShell\Modules;

    C:\Windows\system32\WindowsPowerShell\v1.0\Modules;

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

  6. Close and reopen powershell ise (always as administrator)

  7. Check in the powershell ise -> Modules - if sqlserver is there:

    Enter image description here

  8. If it is not - then something went wrong - otherwise you should be able now to run

    Import-Module sqlserver
    
  9. And as I test in PowerShell:

    Get-SqlAgent -ServerInstance my_server_name

    enter image description here

If it worked fine, you're good to go.