使用MacOS(M2芯片):
我有 Powershell 脚本,需要以管理员身份运行 (sudo)。
要调试脚本,我需要从 pwsh 提示符在调试模式下运行脚本 - 但我不知道如何在调试模式下运行。
就像 Python 一样,我们只需调试即可
python3 -m pdb myscript.py
或者,我在 Macbook 中尝试在 ISE 模式下使用 Powershell 扩展使用 VSCode ——但我努力寻找一种方法在 VSCODE
中以 Sudo/管理员权限运行我的脚本Existing PbiWorkbench (PbiWb) install detected, comparing versions...
Importing PbiWorkbench (PbiWb)...
Adding token to PbiWorkbench secure storage for future updates
Invoking PbiWb module...
OperationStopped: Must run as administrator
PS /Users/wilson>
在终端中,通过运行以下命令以调试模式启动 PowerShell:
pwsh -NoProfile -ExecutionPolicy 绕过 -Command“Set-PSDebug -Trace 1; .\ScriptName.ps1”
然后,您可以使用“Set-PsBreakpoint”cmdlet 在脚本中设置断点。