Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements #1

Open
Rapidhands opened this issue Dec 13, 2020 · 1 comment
Open

Enhancements #1

Rapidhands opened this issue Dec 13, 2020 · 1 comment

Comments

@Rapidhands
Copy link

Hi,
I've discovered your module. Great job. Could i suggest you add more samples for use it.
i.e. : Auto build GUI - How ? Always with the .csv file in input,.. but the .csv file could be build automatically.
In a Main Script :

  • Gather script files (.bat, .cmd, .ps1) in a specific folder (i.e. Scripts )
  • Building the .csv file automatically with info gathered
  1. Section : Auto-completion depending on file name. i.e. If file name begin by "Get", section will be "QUERIES", il the name file begin by "ADD" section will be "NEW", ...
  2. Method : Auto-completion depending on file type (.ps1, .cmd, ...)
  3. Command : auto-completion depending of file Name excluding the prefix of the file Name
  4. Descrption : auto-completion depending of the Help Section in the script
    if .cmd or .bat file : read first line (comment) in the file script
    if .ps1 file : read .SYNOPSIS section
  • Saving the .csv file
  • Call Show-MenuGui cmdlet

With this, anyone could build a dynamic GUI depending of the currents scripts in path

I'm thinking that this could be a real good enhancement to show or describe about your module in your Gibhub

I'm aware that to realize this, there are some prerequisites (Naming convention for script files, Help or comments in script files, ...)

Regards
Olivier

@Rapidhands
Copy link
Author

Something like this

# Gather All Scripts in RootPath 
$AllScripts = Get-ChildItem -Path "$RootPath\Scripts\" -File
#Array Initialization
$Data = @()
#Populate Array
foreach ($Script in $AllScripts)
    {
    $Extension = if  ( $script.extension -eq ".ps1") {"powershell_file"}
                 else{ 
                      if ( ($script.Extension -eq ".bat") -or ($script.Extension -eq ".cmd") )
                        {"cmd"}
                     }
    $ScriptType = ($Script.Name).split("-",2)[0]
    $Synopsis = Get-Content -Path $script.FullName | Select-String -Pattern ".Synopsis" -Context 0,1
    
    # Feed a PSCustomObject
    $objet = [PSCustomObject]@{Section     = $ScriptType
                               Method      = $Extension
                               Command     = $Script.FullName
                               Arguments   = ""
                               Name        = $Script.Name
                               Description = $Synopsis
                               }
    # Feed the FinalArray
    $Data += $objet
    }

# Creating .csv file...
# Path for .csv file
$csvRootPath = "YourPath"
if (Test-Path $csvRootPath\DataForMenu.csv)
    {
    # removing existing .csv file
    Remove-Item -Path $csvRootPath\DataForMenu.csv -Force
    }
$data | Export-Csv -Path $csvRootPath\DataForMenu.csv -Delimiter "," -NoTypeInformation
# Building GUI ...
Show-ScriptMenuGui -csvPath $csvRootPath\DataForMenu.csv

What do you think about this . You can add this as sample (MainScript)
I see a user-case for this :

  • Admin users have no access to the Internet ... (i.e. for secure reason)
  • You have created a bunch of scripts for your colleagues and copy/paste/sendto ... but they don't know how to use them.
  • Answer to them : "Just launch MainScript.ps1 at the root on the root folder. This root folder contains /scripts and /Modules (used by some scripts) /functions (used by some scripts)
  • The GUI (based on your module) shows all essentials info about the scripts they could use

regards
Olivier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant