Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
@dfinke
dfinke / Invoke-OpenAI
Last active November 28, 2022 13:17
Convert natural language commands into executable PowerShell using OpenAI
<#
Aims to grow the understanding of using OpenAI in PoweShell by providing an example of an implementation and references
#>
function Invoke-OpenAI {
<#
.SYNOPSIS
Convert natural language commands into commands in PowerShell
.EXAMPLE
function Invoke-Speak {
param($msg)
Add-Type -AssemblyName System.Speech
$speaker = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speaker.Speak($msg)
}
function getmessage {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dfinke
dfinke / psncal.ps1
Created March 19, 2022 13:39
Print the calendar vertically i.e. the weekdays will be shown in a column, not in a row
function psncal {
<#
.SYNOPSIS
Print the calendar vertically i.e. the weekdays will be shown in a column, not in a row
.EXAMPLE
psncal
.EXAMPLE
psncal 1
@dfinke
dfinke / getreport.ps1
Last active March 20, 2022 13:49
Retrieve issues from one or more repos, exports it to Excel, then pivots on the repo name, open/closed state, and does a count
Get-GHIssueReport 'powershell/powershell','powershell/vscode-powershell','PowerShell/PowerShellEditorServices' -NumberOfPages 3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dfinke
dfinke / tryProfiler.ps1
Created February 17, 2022 00:50
Try PS Profiler and show results in Excel
# Install-Module -Name Profiler
# created by: @nohwnd - twitter - Jakub Jareš
$trace = Trace-Script {
Get-Process |
Select-Object -First 5 Company,Name,handles |
Export-Excel ./tempProfiler.xlsx
}
Remove-Item ./tempProfiler.xlsx -ErrorAction SilentlyContinue
$data = ConvertFrom-Csv @"
Region,State,Units,Price
West,Texas,927,923.71
North,Tennessee,466,770.67
East,Florida,520,458.68
East,Maine,828,661.24
West,Virginia,465,053.58
North,Missouri,436,235.67
South,Kansas,214,992.47
North,North Dakota,789,640.72
function squeeze {
param($s)
$p = $s.IndexOf(' ')
while ($p -gt -1) {
$s = $s -replace ' ', ' '
$p = $s.IndexOf(' ')
}
function add ($a, $b) {
$a + $b
}
function subtract ($a, $b) {
$a - $b
}
$a, $b = 4, 5