Last active
June 19, 2020 13:12
-
-
Save 7cc/32a31d9c3f7f38eb4385d2bb6b03edc9 to your computer and use it in GitHub Desktop.
powershell functions
This file contains 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
# 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