Monthly Archive

Categories

Load format file in a module

Staying with the test-connection function I thought I’d show how to turn the function and format file into a module. This includes how to load the format file in a module.

 

Create a folder TestConnection

 

Copy the format file and the script file that contains the test-connection function into the folder.

 

Rename the script file to TestConnection.psm1

 

Create a module manifest file:

PS> New-ModuleManifest -Path TestConnection.psd1 –RootModule testconnection.psm1 -FormatsToProcess RSPing.Format.ps1xml -CompatiblePSEditions Core

The manifest file should look like this:

#
# Module manifest for module 'TestConnection'
#
# Generated by: Richard
#
# Generated on: 30/06/2019
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'testconnection.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'

# Supported PSEditions
CompatiblePSEditions = 'Core'

# ID used to uniquely identify this module
GUID = 'e260cd41-8023-4a38-8dab-ac8ffbf20163'

# Author of this module
Author = 'Richard'

# Company or vendor of this module
CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) Richard. All rights reserved.'

# Description of the functionality provided by this module
# Description = ''

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = 'RSPing.Format.ps1xml'

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = '*'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = '*'

 

To load the module into your PowerShell session:

PS> Import-Module -Name C:\Scripts\Modules\TestConnection\TestConnection.psd1

 

Substitute the path to your module.

Even simpler than updating the format data manually!

Comments are closed.