Print this Post

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:

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:

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:

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

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:

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:

And start the development environment:

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

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:

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

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

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


5 pings

Skip to comment form

  1. IvoMol

    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.

    1. waldo

      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.
      unstable but latest: github.
      stable: powershellgallery.

  2. Dmitry Katson

    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.

    1. waldo

      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!

  3. Morten Rasmussen

    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.

    1. waldo

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

    2. Morten Rasmussen

      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\\Backup-NAVDatabase.ps1:40 char:31
      + $BackupFileFullPath = Join-Path $Backuplocation $BackupFile
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (H:String) [Join-Path], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

  4. waldo

    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. ArcherPoint Dynamics Developer Digest - vol 126 - Microsoft Dynamics NAV Community

    […] 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. Convert C/AL Objects to AL with PowerShell » waldo's blog

    […] 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. Convert C/AL Objects to AL with PowerShell - Waldo's Blog - Microsoft Dynamics NAV - Dynamics NAV Users - DUG

    […] 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. Convert C/AL Objects to AL with PowerShell - Microsoft Dynamics NAV Community

    […] 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. Creating Powershell Visual app to manage Nav bases – NavCraft

    […] 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

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

%d bloggers like this: