Skip to content

Instantly share code, notes, and snippets.

@sean-m
Created June 20, 2015 03:22
Show Gist options
  • Save sean-m/4d38808f4d8edee8f95a to your computer and use it in GitHub Desktop.
Save sean-m/4d38808f4d8edee8f95a to your computer and use it in GitHub Desktop.
Pseudo anonymous functions in PowerShell for live code loading/patching.
$cd = $(Split-Path -parent $MyInvocation.MyCommand.Definition)
cd $cd
<#
Code that doesn't change goes in this file which just
loads functions and executes them. The function loading
logic could even exist in another while which is dot-included.
#>
while ($true) {
$funcs = gci funcs\*.ps1
$test_funcs = @()
foreach ($f in $funcs) {
$func_file = $f.FullName
$test_funcs += . $func_file
}
$test_funcs | % { $_.Invoke("Hello world") }
Start-Sleep -Seconds 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment