This is just a little helper function that will help you if you have a prerequisite of certain 3rd-party functions being loaded for your script to work. It will either give you are TRUE/FALSE, or a list of the missing functions. Stick it in somewhere at the beginning of your script, and give it an array of functions to test for, and handle the result however you like.

function Test-Function {
This function will check for the existence of loaded functions.
This function will look at the currently loaded functions and report a true or false
based on whether the functions are loaded or not, or list any missing functions if the
ShowMissing parameter is used.
Test-Function 'My-Function'
Will return TRUE if 'My-Function' is found, or FALSE if it's not.
Test-Function @('My-Function1','My-Function2')
Will return TRUE if both functions are found, or FALSE if one, or both, are missing.
Test-Function @('My-Function1','My-Function2') -ShowMissing
Will return a list of any missing functions.
Author: Øyvind Kallstad
Date: 18.04.2014
Version: 1.0
param (
# Name of function(s) to check.
[Parameter(ValueFromPipeline, Position = 0)]
[string[]] $Name,
# If 'true', will list any missing functions.
[switch] $ShowMissing = $false
$return = $true
$missing = @()
foreach ($functionName in $Name) {
if (-not(Test-Path Path "function:\\$($functionName)")) {
$return = $false
$missing += $functionName
if ($ShowMissing) {
Write-Output $missing
else {
Write-Output $return

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s