PowerShell“在创建管道时发生错误" #Requires -Version 3.0 [英] PowerShell "an error occurred while creating the pipeline" #Requires -Version 3.0
问题描述
尝试使用任何#Requires命令时,例如:
When attempting to use any of the #Requires commands, for example:
#Requires -Version 3.0
他们输入以下文字错误:
They error with the text:
创建管道时发生错误. + CategoryInfo:未指定:(:) [],ParentContainsErrorRecordException + FullyQualifiedErrorId:RuntimeException
An error occurred while creating the pipeline. + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : RuntimeException
我已经在ISE和控制台上对此测试了相同的结果,我的版本如下:
I've tested this on ISE and the Console with the same results, my versions are below:
Name Value
---- -----
PSVersion 5.1.14409.1012
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1012
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
推荐答案
发布问题前的最终测试提供了答案:
My final test before posting the question provided the answer:
似乎'#Requires'命令旨在不符合要求的情况下破坏脚本,而不是发布错误,并且在一行上对其进行测试将导致错误.
It seems the '#Requires' commands are designed to break out of the script if it doesn't meet the requirements rather than posting an error, and testing it on a single line will result in an error.
要进行测试,请找到您的PowerShell版本(例如5.1),然后将以下转置5.1与您的(主要.次要)版本一起保存:
To test, find your PowerShell version (e.g. 5.1) and save the following transposing 5.1 with your (major.minor) version:
#Requires -version 5.1
$PSVersionTable.PSVersion
Read-Host
这将在ISE和控制台上都可以使用,即使使用PowerShell运行"也可以提供输出.
This will work on both ISE and the Console, providing an output even if 'Run with PowerShell'.
- 单独使用#Requires-(任意)行将显示错误.
- 在ISE中,只要附带另一行代码,运行选择"将起作用.
- Using the #Requires -(anything) line on its own will display the error.
- In ISE 'Run selection' will work, as long as it's accompanied by another line of code.
这篇关于PowerShell“在创建管道时发生错误" #Requires -Version 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!