offline installs of dbatools

If you work in a secure environment or your computers cannot access the Internet for any reason, you can still install dbatools with ease by downloading the zip from a workstation that does have Internet access 🌈 And now that our module is digitally signed, you can keep your Execution Policy set to AllSigned, too.

There are essentially 3 ways to get the zip of our module

  1. From PowerShell Gallery using Save-Module
  2. From PowerShell Gallery by downloading from powershellgallery.com/api/v2/package/dbatools
  3. By downloading from dbatools.io/zip

Once the file has been downloaded, copy it to your secure server and place it in one of the directories in your $env:PSModulePath (type $env:PSModulePath at the prompt and press enter). This will allow PowerShell to autoload the module, saving you from having to Import-Module each time you start a new session.

PowerShell Gallery

PowerShell Gallery is Microsoft’s official repository for PowerShell modules and scripts. It’s likely unblocked at your organization, so using the Gallery is a great option.

Method 1

If you run Windows 10 or Windows Server 2016, you’ve already got support for the Gallery and can just issue the following command.

Save-Module -Name dbatools -Path C:\temp

This will download the package, unzip it and place it into C:\temp\dbatools. Saving modules and investigating their content is actually a recommended practice by the PowerShell team, as it’s always good to know what you’re installing on your system.

Method 2

If your system is older and you do not have PowerShellGet or you haven’t upgraded to PowerShell 5.1 (which comes with PowerShellGet), then you can just download the zip directly from the Gallery’s API.

Note that this will download a file ending in .nupkg. Simply rename the file to .zip, extract and you’re set. You can also use PowerShell to download the module and rename it, all in one shot.

Invoke-WebRequest -Uri powershellgallery.com/api/v2/package/dbatools -OutFile c:\temp\dbatools.zip

Invoke-WebRequest is a bit slow, however, because of the progress bar, so I usually just download via GUI and rename.

GitHub via dbatools.io/zip

You can also easily download the latest version of our master GitHub repository by simply clicking on dbatools.io/zip. If you’re adventurous, you can even download our latest dev (beta) version at dbatools.io/devzip.

This is just an easy-to-remember redirector to GitHub’s repo zip.

Note that there is a small difference between our GitHub repo and the PowerShell Gallery. The GitHub repo does not include a pre-compiled version of our library (dbatools.dll), while the PowerShell Gallery does. Ultimately, both ways work and there’s really no difference. Excluding the dll from the GitHub repo just made it easier for our developers to avoid conflicts.

Once you’ve extracted the folder, make sure you rename it from dbatools-master or dbatools-development to plain o’ dbatools.

Unblocking DLLs

Our .psm1 takes care of Unblocking DLLs, but if you use the download and unzip method for other PowerShell modules, keep in mind that the DLLs will likely be blocked by default. If this happens, simply run

Get-ChildItem -Recurse C:\path\to\module | Unblock-File

$env:PSMODULEPATH

Just a quick note about $env:PSMODULEPATH. If you’re not familiar with PSMODULEPATH, you may remember PATH from the DOS days and PSMODULEPATH is similar. Any module placed within your $env:PSMODULEPATH will automatically load once you execute a command from that module. Here, you can see the contents of my path and that I manually added my git repo.

Thanks for reading,
- Chrissy

20 thoughts on “offline installs of dbatools

  1. Pingback: Installing dbatools Offline – Curated SQL

  2. Brian Love Reply

    I’ve read much of the site and have just installed the tools.
    This looks very exciting!

  3. Adolfo Martinez Jr Reply

    I’ve installed dbatools via the offline method of zipping and unzipping and then renaming the module to dba tools. Apparently the module shows as available in my session when I run Get-Module. However, there are no available commands to execute. How can I solve this problem?

  4. Rex Reply

    Ugh.

    Have 2008R2 Servers, pplanning for upgrade and consolidation. Was told about the tools by a peer and began loading to access our SQL server as the topology and AD resides in a different “AD tree” as my work station i had to perform some actions on my DB server. 1st, had to upgrade Framework 1st, then install new Powershell, was able to past the signing and a block on the module, then it showed up in powershell ISE last night.

    I dropped out of the ISE modules not showing now. WTF. Stuck Now, tried to reload and getting smo dll error when trying to re-run installer.

    Documentation on doing the installs would. Especially as it relates to transitioning legacy systems.

    • Chrissy LeMaire Post authorReply

      check out dbatools.io/soup2nutz

      in your case, remove everything (uninstall-module or delete from your directories) and try again. Also, I highly recommend using the console (powershell.exe) as opposed to the ISE. If you need a visual, vs code is more desirable.

  5. Andrew Calvett Reply

    Hi,

    I wanted to share the solution to a problem I had with the install to save other people time.

    My environment is locked down so i had to follow the manual download process and copy the module to one of the modules folders set per $env:PSModulePath.

    As i don’t have local admin i could only copy to a modules folder defined on a share but when i installed the module it would fail with “Exception calling “ReadAllText” with “1” argument(s): “The given path’s format is not supported.” ”

    Some testing showed i could use a local path or a mapped drive and dbatools would load, i could have stuck with import-module but i wanted all the auto loading goodness so it needed to be in PSModulePath but initially i could not edit that path because i did not have admin access to get at it through the control panel.

    A little more digging led me back to powershell and a one liner to add the path to PSModulePath and happy days!

    The command was: $env:PSModulePath += “;”

    Hope this is useful for someone else!

    Cheers

    Andrew

  6. David Brown Reply

    How do I install dbatools on Windows Server 2003? I have installed KB968930 which gets me the Windows Management Framework and PowerShell 2.0 but I need dbatools to migrate a database from SQL Server 2003 to SQL Server 2012.

    • Chrissy LeMaire Post authorReply

      dbatools will not work on PowerShell 2.0 (tho some remoting may work). What you’ll want to do is install dbatools on a workstation, then just connect remotely to the two servers by doing -Source win2k3server -Destination sql2012server -BackupRestore -SharedPath … etc.

  7. Brian Reply

    Soooo… how to install??? 🙂 I got as far as extracting the zip and unblocking dlls but am not really clear on how to make it go afterwards.

  8. owen mcgee Reply

    How do you install “offline” dbatools ?
    I have unzipped the file and typed install-module dbatools and I get dbatools not recognized ?
    I did have to install powershell 6.0 to get this far.
    I work in very secure environments that has no access to the internet.

      • Asher Reply

        Chrissy, you need to include this in your install instructions. I see numerous people as well as myself are having problems because of this.

        • Chrissy LeMaire Post authorReply

          Hey Asher,
          It’s a toss-up and I decided to go with listing only the better practice. You won’t need to manually Import-Module if you place the module in the proper place.

          Anyone who needs that skipped this step at the top:

          Once the file has been downloaded, copy it to your secure server and place it in one of the directories in your $env:PSModulePath (type $env:PSModulePath at the prompt and press enter). This will allow PowerShell to autoload the module, saving you from having to Import-Module each time you start a new session.

          At this time, I’d prefer answering the questions one-by-one instead of providing a way that will ultimately teach people to Import-Module every time.

          If you have a suggestion for a better way to explain that things should go into $env:PSModulePath, please let me know.

    • Chrissy LeMaire Post authorReply

      Thanks bruh. Always enjoy reading such encouragement after spending a long time writing an article several years ago 👍🏼 Keep up the good work.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.