Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
. .\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 $_
}
}
}
Owner

gaelcolas commented Apr 20, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment