3

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.

jshizzle
  • 467
  • 1
  • 11
  • 23
  • It should be `Modules`, not `Module`. Please let me know if that sorts it out. Is it the top line in the script? – G42 Aug 14 '17 at 08:46
  • 1
    Sorry, that was a typo. Have corrected this. Yes it's right at the top, however, there's plenty of documentation out there that says this isn't essential and that it simply needs to be on it's own line. – jshizzle Aug 14 '17 at 08:53
  • My bad; it doesn't have to be at the top. Can you confirm [as per docs](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/about_Requires?view=powershell-5.0) it's not in a function, cmdlet or snap-in? Are sucessfully able to manually import the `LyncOnlineConnector`? What troubleshooting steps have you already taken? [Found this bug](https://github.com/PowerShell/PowerShell/issues/3803) but it's related to console, not script – G42 Aug 14 '17 at 09:06
  • 1
    As well as testing within a script I'm testing this on it's own in it's own script to make sure there's nothing else interfering with this. Yes I can manually import all modules. This also happens when running "#requires -Version 3.0". It seems however that the bug mentioned is the issue here as doesn't error when running outside of the ISE. Shame, as intended for this script to be run from that. Thanks for info though. – jshizzle Aug 14 '17 at 12:16

1 Answers1

0

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.

ScriptMonkey
  • 191
  • 1
  • 3
  • 20