Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
. .\lib.common\MethodHelpers.ps1
. .\lib.common\PowerObject.ps1
function Resolve-DNSHost {
Param ()
DynamicParam {
Get-DynamicParamForMethod -method ([System.Net.Dns]::Resolve)
process {
Invoke-MethodOverloadFromBoundParam -method ([System.Net.Dns]::Resolve) -parameterSet $PSCmdlet.ParameterSetName -Parameters $PSBoundParameters
Write-Warning "Error occured: $_"
throw $_
Copy link

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