是否有人知道脚本或 powershell windows 实用程序,或 3rd 方实用程序、codeplex、poshcode 脚本、应用程序等,它们可以读取和扫描 powershell 脚本并详细说明管理单元、提供程序、程序集、cmdlet、函数等等,脚本需要执行。
谢谢。鲍勃。
是否有人知道脚本或 powershell windows 实用程序,或 3rd 方实用程序、codeplex、poshcode 脚本、应用程序等,它们可以读取和扫描 powershell 脚本并详细说明管理单元、提供程序、程序集、cmdlet、函数等等,脚本需要执行。
谢谢。鲍勃。
首先要做的事情:不,我不知道这样的脚本/实用程序。
不过,我怀疑您可以利用 Powershell 的自我解析能力走得更远。
例如,以下脚本:
function test {}
test
$content = gc $args[0]
[System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |
? { $_.Type -eq "Command" } | ft
将自身作为参数给出以下输出:
内容类型 起始长度 StartLine StartColumn EndLine EndColumn ------- ---- ----- ------ --------- ----------- -------- - -------- 测试命令 20 4 3 1 3 5 gc 命令 39 2 5 12 5 14 ? 命令 127 1 6 76 6 77 英尺命令 157 2 6 106 6 108
因此,“命令”类型至少包括函数和 cmdlet。您可以通过取消对这些标记的别名来进一步剖析这一点。
这可能已经可以告诉您一些信息,但与您非常详尽的 Powershell 脚本可能需要的列表相去甚远。
但至少在管理单元或模块的情况下,您可能需要一些魔法才能准确地知道缺少什么。
实际上,我们制作了其中几个实用程序:
http://scriptcop.start-automating.com - 免费在线/可下载的 PowerShell 脚本静态分析 http://scriptcoverage.startautomating.com/ - Powershell 脚本的代码覆盖工具
ShowUI (Get-ReferencedCommand)模块中还有一个工具可以完全满足您的需求。它查看命令中使用的每个命令,以及它们使用的每个命令,以生成必须包含的所有命令的列表。
你像这样使用它: Get-ReferenedCommand -ScriptBlock { Start-MyCommand }
希望这可以帮助