Пример #1
0
        public static IEnumerable <CommandInfo> GetModuleCmdlets(PSCmdlet cmdlet, params string[] modulePaths)
        {
            var getCmdletsCommand = String.Join(" + ", modulePaths.Select(mp => $"(Get-Command -Module (Import-Module '{mp}' -PassThru))"));

            return((cmdlet?.RunScript <CommandInfo>(getCmdletsCommand) ?? RunScript <CommandInfo>(getCmdletsCommand))
                   .Where(ci => ci.CommandType != CommandTypes.Alias));
        }
Пример #2
0
 public static IEnumerable<CmdletAndHelpInfo> GetModuleCmdletsAndHelpInfo(PSCmdlet cmdlet, params string[] modulePaths)
 {
     var getCmdletAndHelp = String.Join(" + ", modulePaths.Select(mp => 
             $@"(Get-Command -Module (Import-Module '{mp}' -PassThru) | Where-Object {{ $_.CommandType -ne 'Alias' }} | ForEach-Object {{ @{{ CommandInfo = $_; HelpInfo = ( invoke-command {{ try {{ Get-Help -Name $_.Name -Full }} catch{{ '' }} }} ) }} }})"
     ));
     return (cmdlet?.RunScript<Hashtable>(getCmdletAndHelp) ?? RunScript<Hashtable>(getCmdletAndHelp))
         .Select(h => new CmdletAndHelpInfo { CommandInfo = (h["CommandInfo"] as PSObject)?.BaseObject as CommandInfo, HelpInfo = h["HelpInfo"] as PSObject });
 }
Пример #3
0
        public static IEnumerable<PSObject> GetScriptHelpInfo(PSCmdlet cmdlet, params string[] modulePaths)
        {
            var importModules = String.Join(Environment.NewLine, modulePaths.Select(mp => $"Import-Module '{mp}'"));
            var getHelpCommand = $@"
$currentFunctions = Get-ChildItem function:
{importModules}
Get-ChildItem function: | Where-Object {{ ($currentFunctions -notcontains $_) -and $_.CmdletBinding }} | ForEach-Object {{ Get-Help -Name $_.Name -Full }}
";
            return cmdlet?.RunScript<PSObject>(getHelpCommand) ?? RunScript<PSObject>(getHelpCommand);
        }
Пример #4
0
        public static IEnumerable<FunctionInfo> GetScriptCmdlets(PSCmdlet cmdlet, string scriptFolder)
        {
            // https://stackoverflow.com/a/40969712/294804
            var getCmdletsCommand = $@"
$currentFunctions = Get-ChildItem function:
Get-ChildItem -Path '{scriptFolder}' -Recurse -Include '*.ps1' -File | ForEach-Object {{ . $_.FullName }}
Get-ChildItem function: | Where-Object {{ ($currentFunctions -notcontains $_) -and $_.CmdletBinding }}
";
            return cmdlet?.RunScript<FunctionInfo>(getCmdletsCommand) ?? RunScript<FunctionInfo>(getCmdletsCommand);
        }
 public static void RunScript(this PSCmdlet cmdlet, ScriptBlock block)
 => cmdlet.RunScript <PSObject>(block.ToString());
 public static void RunScript(this PSCmdlet cmdlet, string script)
 => cmdlet.RunScript <PSObject>(script);