Import-Methods by Joel Bennett 4 years ago
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/162"></script>download | new post
Add functions to the scope for each static method of a type. Originally from Oisin Grehan
GREAT example: . Import-Methods Math
- param([type]$type = $(throw "need a type!"))
- $type | Get-Member -static | Where {$_.membertype -eq "method" } |
- % {
- $func = "function:$($_.name)"
- if (test-path $func) { remove-item $func }
- new-item $func -value "[$($type.fullname)].InvokeMember('$($_.name)','Public,Static,InvokeMethod,DeclaredOnly', `$null, `$null, `$args[0])"
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository