Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
@dfinke
dfinke / Invoke-GitHubChat.ps1
Last active September 19, 2024 23:44
PowerShell script for querying AI models via GitHub API and retrieving chat completions
$prompt = "capital of france?"
$model = "gpt-4o-mini"
# $model = "o1-preview"
$headers = @{
    "Content-Type"  = "application/json"
    "Authorization" = "Bearer $($env:GITHUB_TOKEN)"
}
$body = @{
@dfinke
dfinke / Get-WorkSummary.ps1
Created September 14, 2024 23:10
PowerShell script lists recent files; AI analyzes your work—instantly see what you've accomplished!
param(
$daysOld = 7
)
$targetDir = $(
'D:\mygit\GPTIdeas\Experiments\Livestream-GPT\'
'D:\mygit\PowerShellAIAssistant-ScratchPad'
'D:\mygit\PSAI'
'D:\mygit\PSAIAgent-Stealth-2\'
'D:\temp\Camtasia\scratch\'
@dfinke
dfinke / Show-ExcelSumProduct.ps1
Last active September 9, 2024 08:35
This script exports CSV data to an Excel file, formats it, and applies a SUMPRODUCT formula.
$sumData = ConvertFrom-Csv @"
ProductName, VendorName, TotalSales
Macbook, Apple
Desktop, DELL
RAM, Lenovo
HDD, HCL
Laptop, IBM
Mouse, Acer
"@
@dfinke
dfinke / Show-GitLikeDiff.ps1
Created August 25, 2024 18:31
Git-like Diff Tool in PowerShell
# Git-like Diff Tool in PowerShell
function Compare-Files {
param (
[string]$OldFilePath,
[string]$NewFilePath,
[int]$ContextLines = 3
)
$oldFile = Get-Content -Path $OldFilePath
@dfinke
dfinke / Compare-PicsUsingAI.ps1
Last active August 10, 2024 17:18
AI-powered image comparison in PowerShell using PSAI module
# Install-module PSAI
# Get OpenAI API key from https://platform.openai.com/account/api-keys
# Set $env:OpenAIKey
function Compare-PicsUsingAI {
param(
$pic1,
$pic2
)
@dfinke
dfinke / powershell-agent-team.ps1
Last active July 29, 2024 10:55
The difference between building LLM-powered applications in summer 2024 vs summer 2023?
<#
This PowerShell script is powered by my PSAI and PSAIAgent modules.
PSAI - Is a port of the OpenAI Python SDK
PSAIAgent - Is a PowerShell module that allows you turn an OpenAI LLM into an AI Assistant with memory and tools
Register-Tool - Takes PowerShell functions signatures and creates the JSON to be used by OpenAI
New-Agent - Creates an AI Agent that can be used to interact with OpenAI
Get-AgentResponse - Takes the agent and prompt, calls the OpenAI model, runs the functions if needed and returns the response
#>
@dfinke
dfinke / Singleton.ps1
Created June 28, 2024 13:50
PowerShell Singleton Pattern: Ensure single instance for shared resource management
# Singleton
class Product {
$Name
Product($name) {
$this.Name = $name
}
}

PowerShell Issues FAQ

General

Q: How frequently are issues in the PowerShell repository reviewed? A: The frequency of issue reviews can vary; however, issues are often reviewed when they are newly created. Regular review cycles might also be in place depending on the projectΓÇÖs maintenance policy.

Q: How can I determine if a cmdlet/module is maintained in the PowerShell repository? A: You can use the repository's search function, issue templates, and officially provided documentation to determine if a cmdlet/module is maintained in the powershell/powershell repository.

@dfinke
dfinke / ChatMediator.ps1
Created June 21, 2024 14:06
Demonstrates the implementation of the Mediator Design Pattern in PowerShell
<#
Define an object that encapsulates how a set of objects interact.
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
#>
class ChatMediator {
$users
ChatMediator() {
$this.users = New-Object System.Collections.ArrayList
@dfinke
dfinke / StartComputer.ps1
Last active July 30, 2024 13:53
PowerShell example demonstrating the Facade Design Pattern implementation
class CPU {
freeze() { "$this freezing" | Out-Host }
jump($position) { "$this jump to $position" | Out-Host }
execute() { "$this execute" | Out-Host }
}
class Memory {
load($position, $data) {
"$this load $position $data" | Out-Host