Skip to content

Instantly share code, notes, and snippets.

@7cc
Last active June 19, 2020 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7cc/32a31d9c3f7f38eb4385d2bb6b03edc9 to your computer and use it in GitHub Desktop.
Save 7cc/32a31d9c3f7f38eb4385d2bb6b03edc9 to your computer and use it in GitHub Desktop.
powershell functions
# Function
function F {}
F
# ScriptBlock
& ({})
({}).Invoke()
# PSScriptMethod
$m = New-Module -ScriptBlock {
$val = "Hello"
function Say {
$Script:val += "+"
$val
}
} -AsCustomObject
$m.Say() # Hello+
$m.Say() # Hello++
$m.Say() # Hello+++
# PSMethod
class foo {
static [int]bar() { return 1 }
}
[foo]::bar()
## Delegate
([Action]{
Write-Host 1
Write-Output 2
}).Invoke()
([Func [int]]{ }).Invoke()
([Func [int, bool]]{ $args[0] -ge 5 }).Invoke(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment