Reputation: 91
Problem Description
When I select Run Without Debugging in Visual Studio Code 1.58.2 on the module SampleModule.psm1
function ConvertTo-PascalCase([String []] $words) {
[String] $pascalCaseString = [String]::Empty
foreach ($word in $words) {
$pascalCaseString = $pascalCaseString + ($word.Substring(0,1).ToUpper() + $word.Substring(1))
}
$pascalCaseString = ($pascalCaseString.TrimEnd(',')).Trim()
return $pascalCaseString
}
Export-ModuleMember -Function Convert-ToPascalCase
I keep getting the error message:
InvalidOperation: Cannot run a document in the middle of a pipeline
The screenshot shows it in more detail. I have got this same error message whenever I build any module
Things I Tried That Did Not Work:
How I Know It's an Issue With Running PSM1 Files
If I convert the .psm1 module file back into a plain old Powershell script (*.ps1) script and remove all the Export-Module member commands the script runs just fine.
My Work Around
To execute the module in VSCode I have to dotsource to successfully import the module:
PS C:\Users\griot\SampleModule> .\SampleModule.psm1
PS C:\Users\griot\SampleModule> Import-Module .\SampleModule.psm1
PS C:\Users\griot\SampleModule>
My Questions
Any ideas why I am getting the error message?
What is the recommended way to run and debug PowerShell modules in VSCode?
Upvotes: 7
Views: 9818
Reputation: 51
Looks to me like a typo ConvertTo-PascalCase
was the name of the function.
Convert-ToPascalCase
was the $null
function that got exported
Upvotes: 2