PowerShell为何对已批准动词误报?调试启动失败求助
问题排查与解决
错误信息汇总
- 模块导入警告:
TchPublisherArguments模块中部分命令使用了未批准动词,会降低命令可发现性。可通过Import-Module -Verbose查看具体命令,或用Get-Verb获取官方批准动词列表。 - 核心执行错误:术语
Send-Files未被识别为合法的cmdlet、函数、脚本或可执行程序。
错误详情
MyCommand : BoundParameters : {} UnboundArguments : {} ScriptLineNumber : 303 OffsetInLine : 34 HistoryId : 1 ScriptName : C:\Users\Dick\Documents\tch\code\scripts\PowerShell\modules\TchPublisherArguments\TchPublisherArguments.psm1 Line : "send-local-clear" { Send-Files -target local -clearArchive $true ; Confirm-AndExit } PositionMessage : At C:\Users\Dick\Documents\tch\code\scripts\PowerShell\modules\TchPublisherArguments\TchPublisherArguments.psm1:303 char:34 + "send-local-clear" { Send-Files -target local -clearArch … + ~~~~~~~~~~ PSScriptRoot : C:\Users\Dick\Documents\tch\code\scripts\PowerShell\modules\TchPublisherArguments PSCommandPath : C:\Users\Dick\Documents\tch\code\scripts\PowerShell\modules\TchPublisherArguments\TchPublisherArguments.psm1 InvocationName : Send-Files PipelineLength : 0 PipelinePosition : 0 ExpectingInput : False CommandOrigin : Internal DisplayScriptPosition :
解决步骤
确认
Send-Files定义存在- 检查
TchPublisherArguments.psm1文件中是否定义了Send-Files函数,或该模块是否依赖其他包含此函数的模块。 - 若
Send-Files是外部脚本,需确认其路径已加入PowerShell的$env:Path,或调用时使用完整路径。
- 检查
修复未批准动词问题
- 运行
Import-Module TchPublisherArguments -Verbose,定位所有使用未批准动词的命令。 - 参考
Get-Verb返回的批准动词列表,修改命令名称(比如将Send-Files改为Send-File或Publish-File,匹配功能选择合适动词)。
- 运行
验证模块导入
- 重启PowerShell会话后,重新导入模块:
Import-Module C:\Users\Dick\Documents\tch\code\scripts\PowerShell\modules\TchPublisherArguments\TchPublisherArguments.psm1 -Force - 导入后执行
Get-Command -Module TchPublisherArguments,确认Send-Files(或修改后的命令名)已被正确加载。
- 重启PowerShell会话后,重新导入模块:
检查脚本语法与依赖
- 查看
TchPublisherArguments.psm1第303行附近代码,确认Send-Files调用无拼写错误。 - 确认模块所需的其他依赖项(如.NET程序集、外部脚本)已正确存在或加载。
- 查看
内容的提问来源于stack exchange,提问作者aksarben
相关产品推荐
相关产品推荐

