【发布时间】:2021-08-11 23:10:13
【问题描述】:
我正在开发一个系统管理脚本,该脚本从两个大型/复杂模块中提取 - 一个用于错误记录/报告,另一个用作服务器 API 的库。我遇到了一些非常奇怪的错误,这些错误让我认为这些库中的某些东西使环境处于不良状态。即使在我重新启动 ISE/主机并删除所有复杂代码后,它们似乎仍然存在。这是我目前的测试:
set-psdebug -trace 2
pause
pause
# Initialize Paths and Filenames
$Network_Share = "\\EC2AMAZ-R2G8HFL\Backup"
pause
输出:
PS D:\Scripts\Scripts_7-6> D:\Scripts\Scripts_7-6\test8-11.ps1
Set-PSDebug : Cannot bind parameter 'Trace'. Cannot convert value "2" to type "System.Int32". Error: "Input string was not in a correct format."
At D:\Scripts\Scripts_7-6\test8-11.ps1:1 char:20
+ set-psdebug -trace 2
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSDebug], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetPSDebugCommand
Press Enter to continue...:
pause : The term 'pause' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Scripts\Scripts_7-6\test8-11.ps1:5 char:1
+ pause
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (pause:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
: The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Scripts\Scripts_7-6\test8-11.ps1:8 char:1
+
+ ~
+ CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Press Enter to continue...:
PS D:\Scripts\Scripts_7-6>
如果我没看错,它会抛出关于“2”不是 Int32 兼容值、第二个“暂停”不是可识别命令(尽管第一个和第三个按预期工作!)的错误,最后是第 8 行的空行被解释为命令(尽管第 2、4 和 10 行的空行不是)。
有些东西真的让我的环境陷入了循环,我什至不知道从哪里开始解决这个问题。谁能指点我一些可以帮助我弄清楚发生了什么的资源?
编辑:为 Set-PSDebug 添加语法
PS D:\Scripts\Scripts_7-6>> Help Set-PSDebug
NAME
Set-PSDebug
SYNOPSIS
Turns script debugging features on and off, sets the trace level, and toggles strict mode.
SYNTAX
Set-PSDebug [-Off] [<CommonParameters>]
Set-PSDebug [-Step] [-Strict] [-Trace <Int32>] [<CommonParameters>]
DESCRIPTION
The Set-PSDebug cmdlet turns script debugging features on and off, sets the trace level, and toggles strict mode.
When the Trace parameter is set to 1, each line of script is traced as it is executed. When the parameter is set to 2, variable assignments, function calls, and script calls are also traced. If the Step parameter is specified, you are prompted before each line of the script is executed.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/p/?linkid=289612
Debug-Process
Set-PSBreakpoint
Set-StrictMode
Write-Debug
about_Debuggers
REMARKS
To see the examples, type: "get-help Set-PSDebug -examples".
For more information, type: "get-help Set-PSDebug -detailed".
For technical information, type: "get-help Set-PSDebug -full".
For online help, type: "get-help Set-PSDebug -online"
【问题讨论】:
-
运行
Help Set-PSDebug并发布函数/cmdlet 的语法。 -
@AbrahamZinala 将结果添加到上面的帖子中。我使用的语法是从 MS 脚本演示中复制而来的,看起来很合理。不知道为什么“2”不是整数。
标签: powershell