PowerShellGet & waldo’s PowerShell Modules

Since Microsoft Dynamics NAV 2017, the VM images that Microsoft (Freddy) makes available on Azure, contains the PowerShellGet module. Freddy mentioned that in one of his blogposts about the Azure images. For me this was quite new, but sounded interesting, so I looked into it.

What is “PowerShellGet”?

Well, PowerShellGet is a module that is now by default present on Windows 10 (and I assume also on Windows Server 2016 – which is by the way the new OS for all the upcoming demo environments!) that makes it much easier for you to find, download and install PowerShell modules that are made available in the PowerShell Gallery: https://www.powershellgallery.com/ . If PowerShellGet not available on your OS, you can download it from that web page.

So, when you installed the module, you get PowerShell CmdLets that can search for PowerShell modules, install them, load them, and make them available. So in a way, from within a script, you can make available PowerShell modules.

The thing really makes me think of the way we installed stuff on Linux many years ago, with the apt-get command.

I made my PowerShell modules available on the PowerShell Gallery

Which you might have expected – hence the title :-). You can find them easily when you search for “waldo” on the PowerShell Gallery. But that’s not really how you should use it. You have to use it from PowerShell (in my opinion).

Let’s show that in this small walkthrough

I just created myself an image of The NAV Development Tools Preview – January Update (oh yes, there is a new update on the New DEV tools! 🙂 ). But as said, this should work on any Win10 or WinServer2016 – or any system where you installed the PowerShellGet module.

Just open PowerShell as an administrator (since you’re installing modules, it seems like a good idea to do that as admin…). Let’s first search for my modules from within PowerShell:

Find-Module | where Author -eq waldo

The “Find-Module” is part of the “PowerShellGet” module, which is going to search for modules in the gallery. So in this case, I will search of all my modules in the gallery.

So if we execute this:

Find-Module | where Author -eq waldo | Install-Module

with the “install-module” (also part of the “PowerShellGet” module), it will “install all waldo’s modules :-)”. So when you get this:

You simply say “yes to all”, since you trust me (IF you trust me :-)). It will download and install the modules. You’ll find the downloaded files in “C:\Program Files\WindowsPowerShell\Modules”.

Since it will just have downloaded them, you need to still import them like you have to import any module before you can use them in your runspace .. So therefore:

Import-Module Cloud.Ready.Software.NAV

With this line, you can show all the functions that you have just made available by downloading the modules from the PowerShell Gallery.

get-command -Module Cloud.Ready.Software.*

So, let’s see if it works

Ok, let’s try some of my functions on this Azure image.

In order to do that, we will first import the standard NAV commandlets. And I made that somewhat easier with this function:

Import-NAVModules

This function will put all the commands that are necessary to load the default NAV CmdLets to your clipboard. Simply past and execute. I haven’t managed to import the module in the global context from within the function (seems like a bug in PowerShell) – but this did the trick quite nicely as well :-). So paste the content of the clipboard in the shell, and execute!

Now, let’s set up a new sandbox environment (database and NST) by simply copy everything from the “NAV” instance:

Get-NAVServerInstance -ServerInstance 'NAV' | Copy-NAVEnvironment -ToServerInstance sandbox

And start the development environment:

Start-NAVIdeClient sandbox

This is how I always build my development environments on dev images – local or in the cloud. To remove, you can simply do:

Remove-NAVEnvironment -ServerInstance sandbox

Be careful with that one. It’s removing the database and server instance – so be sure you have a backup when needed :-).

What if you have updated your modules?

Well, you can imagine there is a PowerShellGet function for that as well: Update-Module. You can simply do:

Find-Module | where author -eq waldo | Update-Module

This PowerShellGet-module is awesome! :-). Thanks, Freddy, for introducing me :-).

5.00 avg. rating (98% score) - 2 votes

Permanent link to this article: https://www.waldo.be/2017/01/17/powershellget-waldos-powershell-modules/

8 comments

5 pings

Skip to comment form

    • IvoMol on January 19, 2017 at 9:35 am
    • Reply

    Hi, looks good!

    What will be primary source of your code in future? GitHub or PowerShellGet?
    For which version NAV (2017/2016) will be modules in PowerShellGet written?

    Thank you.

      • waldo on January 25, 2017 at 11:48 am
        Author

      Good question ;-). Well, Github is my primary source – there, I’ll have my source control.
      All (in my opinion) stable releases will be pushed to PowerShellGallery.
      So:
      unstable but latest: github.
      stable: powershellgallery.

    • Dmitry Katson on March 16, 2017 at 3:42 pm
    • Reply

    Hi Waldo, Great job.
    Started use it. Most i like Set-Navuidoffset ! Great =)

    I did not found creation of new NAVWebServerInstance . Will be great if you will add it in Copy-NAVEnvironment for example.

      • waldo on March 16, 2017 at 3:47 pm
        Author

      I already added it in the New-NAVEnvironment, but indeed, not yest in the Copy.. .
      I’ll add it on the issuelist ;-).

      thanks for the feedback!

    • Morten Rasmussen on February 21, 2018 at 9:10 am
    • Reply

    Hi Waldo,

    Will this Copy-NAVEnvironment only work if the nav server and database are on the same server, Can´t seem to get it to work if the Database and nav server is seperate on their own server.

      • waldo on February 21, 2018 at 10:27 am
        Author

      I’m afraid you’re right – I always use it on local VMs.
      What are the errors you get?

      • Morten Rasmussen on February 21, 2018 at 11:04 am

      Seems the problem are that is tries to locate the backup drive on the Nav server but the drive exist on the database server

      Join-Path : Cannot find drive. A drive with the name ‘H’ does not exist.
      At C:\Program Files\WindowsPowerShell\Modules\Cloud.Ready.Software.NAV\1.0.0.14\Backup-NAVDatabase.ps1:40 char:31
      + $BackupFileFullPath = Join-Path $Backuplocation $BackupFile
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (H:String) [Join-Path], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

  1. True – It looks like it completes the backup, but it obviously isn’t able to find it, because it’s on a remote location.. .

  1. […] his recent blog post, PowerShellGet & Waldo’s PowerShell Modules, Waldo explains what PowerShellGet is, why it is important, where to find the PowerShell Gallery […]

  2. […] yourself .. here is an example which you can execute straight on the NAV Developer Preview VM. It installs my modules, and executes the conversion for all “wizards” in the database of the ServerInstance […]

  3. […] yourself .. here is an example which you can execute straight on the NAV Developer Preview VM. It installs my modules, and executes the conversion for all “wizards” in the database of the ServerInstance […]

  4. […] yourself .. here is an example which you can execute straight on the NAV Developer Preview VM. It installs my modules, and executes the conversion for all “wizards” in the database of the ServerInstance […]

  5. […] As you probably know, Powershell is a very usefull tool to manage Nav base and automate administrative tasks. If you don’t hear about Waldo’s Powershell module you need to visit the following link. He create a lot of usefull functions like Add-NAVEnvironmentCurrentUser, that can be used when you are local administrator but not set in Nav base users. http://www.waldo.be/2017/01/17/powershellget-waldos-powershell-modules/ […]

Leave a Reply

Your email address will not be published.

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