Template Menu-Driven PowerShell Tool

<#
.SYNOPSIS
Template Menu-Driven PowerShell Tool

.DESCRIPTION
This script provides a template for a menu-driven PowerShell tool that can be customized
for various administrative or analysis tasks.

.NOTES
File Name      : TemplateMenuTool.ps1
Author         : [Your Name]
Prerequisite   : PowerShell V5.1 or later
Version        : 1.0
Date           : [Current Date]

.EXAMPLE
.\TemplateMenuTool.ps1
#>

# Global variables
$global:reportPath = "$env:USERPROFILE\Desktop\Analysis_Report_$(Get-Date -Format 'yyyyMMdd_HHmmss').html"

<#
.SYNOPSIS
Displays the main menu of the tool.
#>
function Show-Menu {
    Clear-Host
    Write-Host "=== Template Menu-Driven Tool ===" -ForegroundColor Cyan
    Write-Host "1. Set Target (e.g., computer, path, etc.)"
    Write-Host "2. Perform Analysis Task 1"
    Write-Host "3. Perform Analysis Task 2"
    Write-Host "4. Perform Analysis Task 3"
    Write-Host "5. Perform Analysis Task 4"
    Write-Host "6. Perform Analysis Task 5"
    Write-Host "7. Generate Comprehensive HTML Report"
    Write-Host "8. Exit"
}

<#
.SYNOPSIS
Sets the target for analysis (e.g., computer name, file path, etc.).
#>
function Set-Target {
    $target = Read-Host "Enter the target for analysis (e.g., computer name, file path)"
    if (-not [string]::IsNullOrWhiteSpace($target)) {
        $global:target = $target
        Write-Host "Target set to: $global:target" -ForegroundColor Green
    } else {
        Write-Host "Invalid target. Please try again." -ForegroundColor Red
    }
}

<#
.SYNOPSIS
Performs Analysis Task 1.

.OUTPUTS
Array of PSObjects containing analysis results.
#>
function Perform-AnalysisTask1 {
    Write-Host "`nPerforming Analysis Task 1..." -ForegroundColor Yellow
    # Add your analysis logic here
    $results = @([PSCustomObject]@{
        Property1 = "Value1"
        Property2 = "Value2"
    })
    $results | Format-Table -AutoSize
    return $results
}

<#
.SYNOPSIS
Performs Analysis Task 2.

.OUTPUTS
Array of PSObjects containing analysis results.
#>
function Perform-AnalysisTask2 {
    Write-Host "`nPerforming Analysis Task 2..." -ForegroundColor Yellow
    # Add your analysis logic here
    $results = @([PSCustomObject]@{
        Property1 = "Value1"
        Property2 = "Value2"
    })
    $results | Format-Table -AutoSize
    return $results
}

<#
.SYNOPSIS
Performs Analysis Task 3.

.OUTPUTS
Array of PSObjects containing analysis results.
#>
function Perform-AnalysisTask3 {
    Write-Host "`nPerforming Analysis Task 3..." -ForegroundColor Yellow
    # Add your analysis logic here
    $results = @([PSCustomObject]@{
        Property1 = "Value1"
        Property2 = "Value2"
    })
    $results | Format-Table -AutoSize
    return $results
}

<#
.SYNOPSIS
Performs Analysis Task 4.

.OUTPUTS
Array of PSObjects containing analysis results.
#>
function Perform-AnalysisTask4 {
    Write-Host "`nPerforming Analysis Task 4..." -ForegroundColor Yellow
    # Add your analysis logic here
    $results = @([PSCustomObject]@{
        Property1 = "Value1"
        Property2 = "Value2"
    })
    $results | Format-Table -AutoSize
    return $results
}

<#
.SYNOPSIS
Performs Analysis Task 5.

.OUTPUTS
Array of PSObjects containing analysis results.
#>
function Perform-AnalysisTask5 {
    Write-Host "`nPerforming Analysis Task 5..." -ForegroundColor Yellow
    # Add your analysis logic here
    $results = @([PSCustomObject]@{
        Property1 = "Value1"
        Property2 = "Value2"
    })
    $results | Format-Table -AutoSize
    return $results
}

<#
.SYNOPSIS
Generates a comprehensive HTML report of all analyses.

.PARAMETER AllResults
Hashtable containing all analysis results.

.OUTPUTS
Saves an HTML report to the desktop.
#>
function Generate-HTMLReport {
    param([hashtable]$AllResults)

    Write-Host "`nGenerating Comprehensive HTML Report..." -ForegroundColor Yellow
    $reportContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Analysis Report</title>
    <style>
        body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; }
        h1, h2, h3 { color: #0078D4; }
        table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
    </style>
</head>
<body>
    <h1>Analysis Report</h1>
    <p>Generated on: $(Get-Date)</p>
    <p>Target: $global:target</p>

    <h2>Analysis Task 1 Results</h2>
    $($AllResults.Task1Results | ConvertTo-Html -Fragment)

    <h2>Analysis Task 2 Results</h2>
    $($AllResults.Task2Results | ConvertTo-Html -Fragment)

    <h2>Analysis Task 3 Results</h2>
    $($AllResults.Task3Results | ConvertTo-Html -Fragment)

    <h2>Analysis Task 4 Results</h2>
    $($AllResults.Task4Results | ConvertTo-Html -Fragment)

    <h2>Analysis Task 5 Results</h2>
    $($AllResults.Task5Results | ConvertTo-Html -Fragment)
</body>
</html>
"@

    $reportContent | Out-File -FilePath $global:reportPath
    Write-Host "Report generated and saved to: $global:reportPath" -ForegroundColor Green
}

# Main program loop
$allResults = @{}

do {
    Show-Menu
    $choice = Read-Host "`nEnter your choice (1-8)"

    switch ($choice) {
        "1" { Set-Target }
        "2" { $allResults.Task1Results = Perform-AnalysisTask1 }
        "3" { $allResults.Task2Results = Perform-AnalysisTask2 }
        "4" { $allResults.Task3Results = Perform-AnalysisTask3 }
        "5" { $allResults.Task4Results = Perform-AnalysisTask4 }
        "6" { $allResults.Task5Results = Perform-AnalysisTask5 }
        "7" { Generate-HTMLReport -AllResults $allResults }
        "8" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
        default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
    }

    if ($choice -ne "8") {
        Read-Host "`nPress Enter to continue..."
    }
} while ($choice -ne "8")

This Template Menu-Driven Tool includes:

  1. A menu-driven interface for easy navigation.
  2. Placeholder functions for five different analysis tasks.
  3. A function to set a target for analysis (which can be customized based on your needs).
  4. A function to generate an HTML report of all collected data.
  5. Basic error handling and user input validation.

Key features:

  • Easy-to-customize menu structure
  • Placeholder functions for various analysis tasks
  • Ability to set and use a global target variable
  • HTML report generation capability
  • Modular design for easy expansion and modification

To use this template effectively:

  1. Replace the placeholder analysis functions (Perform-AnalysisTask1, Perform-AnalysisTask2, etc.) with your specific analysis logic.
  2. Customize the Set-Target function to handle the type of target you need (e.g., computer name, file path, etc.).
  3. Modify the menu options and corresponding switch statement in the main program loop to match your specific tasks.
  4. Adjust the HTML report generation function to include the specific results you want to display.
  5. Add any necessary module imports or additional global variables at the beginning of the script.

This template provides a solid foundation for creating various types of menu-driven PowerShell tools for system administration, security analysis, or any other task that requires user interaction and multiple analysis steps.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *