PowerShell is designed to be expanded. For example, by adding the Group Policy module, you can utilize PowerShell to help manage the GPOs in your environment. Not all modules are installed on every Windows client/server. The function below is designed to help you determine if a module is present. To use it, simply call the Confirm-Module cmdlet with the name of the module as the parameter. The function will return a $TRUE if the module is present and a $FALSE if it is not.
<#
.SYNOPSIS
Confirms if a module is available.
.DESCRIPTION
Confirms if the provided parameter is available on
the local client.
.PARAMETER ModuleName
The name of the module who’s presence is being checked.
.EXAMPLE
Confirm-Module ActiveDirectory
Checks to see if the ActiveDirectory module is
present on the local machine
Returns True is present and False if not.
.OUTPUTS
Boolean
.Link
Get-Module
.NOTES
============================================
Author: Jason A. Yoder, MCT
WebSite: www.MCTExpert.com
BlogSite: www.MCTExpert.Blogspot.com
============================================
#>
Function Confirm-Module
{
Param ($ModuleName = $(Throw "You need to provide a module name."))
# Place the name of the module from Get-Module into
# the variable $Data
$Data = (Get-Module -ListAvailable -Name $ModuleName).name
# If the contents of $Data is equal to the variable
# $ModuleName, the module is present, return
# True. If not, return $False.
If ($Data -eq $ModuleName){Return $True}
Else {Return $False}
}
Comments