#requires ParentContainsErrorRecordException

Viewed 1905

I'm trying to add the following to my script:

#Requires -Modules LyncOnlineConnector

but keep getting the following error:

An error occurred while creating the pipeline.
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RuntimeException

Not finding a lot of information on this error linked to this PowerShell requirement. Any ideas?

I'm running PowerShell v5, running this on it's own line and have a space between this line and any other comments/commands.

1 Answers

Running #Requires on its own line will result in the error, it needs other script to run against in order to work. I've come across the same thing, and posted the question and answer here: [PowerShell "an error occurred while creating the pipeline" #Requires -Version 3.0

The following example will work:

#Requires -Modules LyncOnlineConnector
$PSVersionTable.PSVersion

Providing the following error if the requirements are not met:

The script 'Test.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: LyncOnlineConnector.

By design, the script will close if run non-interactively via a console.

Related