Created
June 29, 2025 19:02
-
-
Save dfinke/c872806290a1f14f51d9c85d24979c78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 📦 Install-Module: PSAISuite | |
# 🔗https://github.com/dfinke/psaisuite | |
# Get-ChatProviders | |
# PSAISuite supports 13 providers, and their models. | |
# $model = "github:openai/gpt-4.1" | |
$model = "anthropic:claude-opus-4-20250514" | |
$scriptContent = Get-Content .\AnalyzeSampleScript.ps1 | |
$prompt = Get-Content .\PowerShellScriptAnalyzerPrompt.md -Raw | |
$response = $scriptContent | Invoke-ChatCompletion -TextOnly $prompt $model | |
$response | Set-Content .\AnalysisResult.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Analysis and Educational Enhancement Guide
Initial Documentation
Script Purpose and Requirements
Purpose: This PowerShell script identifies resource-intensive processes on your computer and saves the information to a CSV file.
Real-World Analogy: Think of this script as a "resource detective" - like a building inspector who walks through a facility identifying which rooms are using the most electricity and water, then creates a report of the biggest resource consumers.
Requirements:
Input: None required - the script automatically examines all running processes
Output: A CSV file named "H.csv" containing process names, CPU usage, and memory consumption
Educational Comments and Explanations
Enhanced Code with Educational Comments
PowerShell-Specific Concepts Explained
The Pipeline Magic
The pipeline (
|
) in PowerShell is like an assembly line in a factory. Each station (command) does one specific job and passes the result to the next station. In our script:Get-Process
puts all processes on the conveyor beltForEach-Object
examines each oneSort-Object
reorganizes themExport-Csv
packages them into a fileThe Mysterious $_
Think of
$_
as "the thing I'm currently looking at." When you're sorting through a box of toys,$_
would be whichever toy is in your hand at that moment.Object Properties
PowerShell treats everything as objects with properties. A process object is like a person's ID card with different fields:
Process Breakdown
Step-by-Step Data Flow