Question:
I’d basically like to use reflection in Powershell, and after dynamically finding the methods I’d like to invoke using standard powershell commands, I ended up with a MemberDefinition object and not much clue as to how to invoke it. I’m not positive I can, so if you have experience you can just say not to do it this way. I know I can drop into the Assembly namespace, but didn’t know if I could do something like this:
1 2 3 |
$method = $ie | get-member -type method | ? { $_.name -eq 'span' } invoke-member $ie $method |
The $method
variable is of type Microsoft.PowerShell.Commands.MemberDefinition, is this even possible?
Thanks, Matthew
Answer:
Sounds like you’re pretty familiar with .NET, why not just drop down and use reflection directly?
1 2 3 4 5 6 |
PS> $d = Get-Date PS> $t = $d.GetType() PS> $t.InvokeMember("ToUniversalTime", "Public,InvokeMethod,Instance", $null, $d, $null) Saturday, March 31, 2012 3:10:51 AM |