PowerShell 2.0: One Cmdlet at a Time 74 Test-ModuleManifest

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Test-ModuleManifest cmdlet.

What can I do with it?

PowerShell 2.0 introduces the concept of modules; essentially they are the evolution of snapins from PowerShell 1.0.  A module creator could use Test-Module to ensure that files listed in a *.psd1 file, possibly created by New-ModuleManifest , are valid.

Example:

Test that the C:\Users\User1\Documents\WindowsPowerShell\Modules\Logfile-Module\Logfile-Module.psd1 (created in the New-ModuleManifest example) is valid.

Test-ModuleManifest -Path ‘C:\Users\User1\Documents\WindowsPowerShell\Modules\Logfile-Module\Logfile-Module.psd1’

You will see that this returns an object for the module. If any files were not valid then an error message would be produced.

To obtain a tidy True or False answer the ErrorAction parameter can be used with the Silently Continue value to surpress any errors. By then examining the current value of the $? automatic variable such an answer can be obtained.

Test-ModuleManifest -Path ‘C:\Users\User1\Documents\WindowsPowerShell\Modules\Logfile-Module\Logfile-Module.psd1’ -ErrorAction SilentlyContinue $?

You will see the result in this case is True.

How could I have done this in PowerShell 1.0?

This functionality was not avaliable with snapins in PowerShell 1.0

1000 things 1% better