Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

Verify PowerShell Module Manifests

$
0
0

Summary: Ed Wilson, Microsoft Scripting Guy, talks about verifying Windows PowerShell module manifests.

Microsoft Scripting Guy, Ed Wilson, is here. One of the things that is cool about Windows PowerShell is that it is self-describing. I can type Get-Member or Get-Command and find out what a Windows PowerShell cmdlet is all about. Then there is Get-Help, which also provides way cool information. When cmdlets ship in Windows PowerShell modules, there are additional tools available. I can use Get-Module to see what a module contains.

But there is more…

I can look at the module manifest. When I create a Windows PowerShell module, I always like to create a module manifest. This is more important than it was, say, back in the Windows PowerShell 2.0 days. In fact, if I want to share my module with others, it is essential that I provide a manifest.

About module manifests

Windows PowerShell module manifests are files that have a .psd1 file extension. They are simple text files. Here is an example of a module manifest from the PowerShellGet module:

Image of command output

To find the path to a module, I can use the Path property from the PSModuleInfo object, which is returned by the Get-Module cmdlet, for example:

PS C:\Users\mredw> (Get-Module PSReadline).path

C:\Program Files\WindowsPowerShell\Modules\PSReadline\1.1\PSReadLine.psm1

Note that sometimes this points to the module, and other times, it points to the module manifest. Here is an example of one that points to a module manifest:

PS C:\Users\mredw> (Get-Module Microsoft.PowerShell.Utility).path

C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1

Test the manifest

If my path command points to a .psd1 file, I can directly use the Path property to test the module manifest. This is shown here:

Image of command output

There is a lot of information returned by the Test-ModuleManifest cmdlet. The important thing is that in Windows PowerShell 5.0, it also verifies the paths to all associated files. In this way, the Test-ModuleManifest cmdlet is also a troubleshooting tool.

I can use the ModuleBase property to find the location of a module, and therefore, to find the module manifest. This is shown here:

PS C:\> gci (Get-Module PSReadline).modulebase -Filter *.psd1

    Directory: C:\Program Files\WindowsPowerShell\Modules\PSReadline\1.1

Mode            LastWriteTime         Length    Name

----                     -------------                ------        ----

-a----        7/10/2015   7:02 AM            787 PSReadline.psd1

I can then pipe the output to the Test-ModuleManifest cmdlet and examine the manifest:

PS C:\> gci (Get-Module PSReadline).modulebase -Filter *.psd1 | % {Test-ModuleManifest -Path $_.fullname}

ModuleType    Version    Name          ExportedCommands

----------              -------           ----                   ----------

Script     1.1        PSReadline             {Get-PSReadlineKeyHandl...

That is all there is to examining module manifests. Join me tomorrow when I will talk about more cool stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy


Viewing all articles
Browse latest Browse all 3333

Trending Articles