Install-Package... then what...

Hi All,


I installed a package which I found with Find-Package and the Nuget package provider. With Get-Package I verified that it was installed. But how do I use that package in a powershell script?



  • Though you do not say what module / package you down loaded, you call it like any other module / package installed on your system that exposes its cmdlets.

    All PoSH cmdlets on your system by default are packages/modules.

    You can list all loaded modules / packages this way...


    ... or list all available modules on your system, this way...

    Get-Module -ListAvailable

    These will show what cmdlets are in the module / package.

    For PoSH, when you use a cmdlet, it auto loads the module so its cmdlets work.

    So, say I am on a Windows server with RSAT features enabled or I am on a client and download ...


    ...and install the RSAT tools, I can just used the cmdlets from RSAT (there are several packages in the RSAT toolset).

    RSAT include the Active Directory cmdlets. I can either just type...


    ... and PoSH will autoload the ActiveDirectory module / Package or I can type...

    Import-Module -Name ActiveDirectory

    ... So, virtually the same thing.

    So, for the package / module you downloaded, just view the help file on how to use its cmdlets / functions etc.

    Of visit the MS PowerShell gallery...


    ... which is really where you got this module from using what you did, search for the module / package name you downloaded and follow the help information provided.
  • In reply to postanote:

    Thanks for the reply. You were right I was not complete in my explanation... :-)

    I found a library on Github (Nlight) and I want to leverage the DelimitedTextRecordReader/Writer classes to experiment with importing CSV-files. I am not a .Net developer but a PS enthusiast so I was wondering if I could leverage this library in PS.

    First I had to register NGet as a new package source:
    Register-PackageSource -Name -Location -Force -Trusted -ProviderName NuGet

    When I use Find-Package NLight i get:
    Name Version Source Summary
    ---- ------- ------ -------
    NLight 1.1.6 Toolbox for .NET projects

    With Install-Package NLight I get a bunch of packages installed in the folder C:\Program Files\PackageManagement\NuGet\Packages.

    Using Get-Package NLight I get
    Name Version Source ProviderName
    ---- ------- ------ ------------
    NLight 1.1.6 C:\Program Files\PackageManag... NuGet

    So far so good. And then... what to do?... :-D. The idea is to create a wrapper/module around those classes but I cannot find the right way to do create/access them.

    I have seen some projects on Github where they leverage a .Net lib (e.g. the Nancy lib) with PS ( But it seems quite complex. I cannot find good blogs/sites where it is explained how to incorporate .Net libs in PS.

    Maybe PS is not the right environment to incorporate .Net libraries. I am learning the do's and don'ts with PS so any help and pointers in the right direction would be great.


  • In reply to Kjoebie:

    No worries.

    I never heard of Nlight, so no real comment on it. Yet, PowerShell native provide cmdlets for text file import, Csv and xml. Specifically, the Import-Clixml and Import-Csv cmdlets.

    What is it about Nlight which is of interest that the built-in ones above cannot provide? The whole idea about importing text data with the import-cmdlets, is to turn them into PoSH object for whatever work you need to do with the file.

    Or maybe you are just experimenting as a learning effort? Which is a good thing, as PoSH is all about discovery and what is possible. Most things are built-in, many things you have to be a bit more creative to get what you need as at results.

    Well a quick look at the Git repo source, shows, it’s all MS C# classes. This means you have to bring (instantiate) that class into your PoSH session in order to use it.  There are several articles on how to use .Net classes in PoSH.

    PoSH is requires .NET to work at all. When you look at each of the PoSH (WMF), you see that you must be on a specific version of .Net Framework, based on the PoSH (WMF) version you install. So, it can use all the .NET classes just as any other programming language.

    # PowerShell: How to Create and Use Classes

    # Why Use .NET Framework Classes from Within PowerShell?

    # Use PowerShell to Work with the .NET Framework Classes

    Using CSharp (C#) code in Powershell scripts

    # Implementing a .NET Class in PowerShell v5

    Here is the MVA (Microsoft Virtual Academy) course on PoSH specifically on classes.

    Another 2hr training video on using / creating classes for use in PoSH
    # Virtual PowerShell User Group - March 2015

    So, you will note, from the above, that whole Nuget import registration and PoSH use case you are after, this may have been a non-sequitur in the stream of thought. As one can literally copy a defined class in another .Net language repo / source (or create your own) and use it in PoSH.

    Point of Note, if you did not know already, PowerShellGet (built-in to PoSHv5) and as a install on PoSH v4 is the PoSH version of get, which Find-Module is part of and brings down packages / module from the PowerShell Gallery. You could have also chosen to use Chocolatey instead. ‘’.