views:

49

answers:

1

Hi,

Does anybody know of a script or powershell windows utility, or 3rd party utility, codeplex, poshcode script, app, whatever etc, which can read and scan a powershell script and detail what snapins, providers, assemblies, cmdlets, functions, etc, etc, etc, the script needs to execute.

Thanks. Bob.

+1  A: 

First things first: No, I don't know of such a script/utility.

I suspect, though, that you can get pretty far with Powershell's capabilities of parsing itself.

For example, the following script:

function test {}

test

$content = gc $args[0]
[System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |
   ? { $_.Type -eq "Command" } | ft

given itself as argument yields the following output:

Content                  Type          Start         Length      StartLine    StartColumn        EndLine      EndColumn
-------                  ----          -----         ------      ---------    -----------        -------      ---------
test                  Command             20              4              3              1              3              5
gc                    Command             39              2              5             12              5             14
?                     Command            127              1              6             76              6             77
ft                    Command            157              2              6            106              6            108

So, the "Command" type includes at least functions and cmdlets. You can further dissect this by un-aliasing those tokens.

This probably can tell you a little already but comes nowhere close to your pretty exhaustive list of what Powershell scripts could require.

But at least in the case of snap-ins or modules you probably need some magic anyway to know precisely what's missing.

Joey
The pspaser tokenizer. I'd forgotten about that.
scope_creep