Created
April 20, 2016 21:44
-
-
Save gaelcolas/9667d56714f3254cb2ebd5dc76b1956d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
. .\lib.common\MethodHelpers.ps1 | |
. .\lib.common\PowerObject.ps1 | |
function Resolve-DNSHost { | |
[cmdletBinding()] | |
Param () | |
DynamicParam { | |
Get-DynamicParamForMethod -method ([System.Net.Dns]::Resolve) | |
} | |
process { | |
try | |
{ | |
Invoke-MethodOverloadFromBoundParam -method ([System.Net.Dns]::Resolve) -parameterSet $PSCmdlet.ParameterSetName -Parameters $PSBoundParameters | |
} | |
catch | |
{ | |
Write-Warning "Error occured: $_" | |
throw $_ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an example to use my quick hack MethodHelpers.ps1 to wrap .Net methods into PowerShell commandlet with little code.
That also allows to extend the features by adding parameters or processing in the param block or begin/process/end blocks.
There are limitations with some constructors or methods when they have similar constructors and/or use references of objects instead of variable.
The main problem with this implementation (in my opinion, there might be others) is that it relies on the [type]::method.OverloadDefinitions which is a string, that I parse using regex (quite simple and not really validating anything, as I did that for log4net which was pretty consistent).
Feel free to point me to flaws or issues and I may try to improve the code.