powershell reflection command execution

  • Thread starter Thread starter Arathij
  • Start date Start date
A

Arathij

Guest
Hi ,

I have C# application to check if the ExchangeOnlineManagemnt ,module is installed I am trying to do with reflection as the configuration is "Any CPU" which I cannot chnage, hence usign this approach

please help here as I get error in the res1 as

Cmdlets derived from PSCmdlet cannot be invoked directly.


=================

var asm = Assembly.LoadFile(@"c:\temp\System.Management.Automation.dll");
var type = asm.GetType("Microsoft.PowerShell.Commands.GetModuleCommand");


var runnable = Activator.CreateInstance(type) as GetModuleCommand;

runnable.ListAvailable = SwitchParameter.Present;
runnable.Name = new string[] { "ExchangeOnlineManagement" };
var res1 = runnable.Invoke(); //res1 no resuts it shows error

Continue reading...
 
Back
Top