Can I create the variables and launch the methods of my classes in PowerShell hosted by me?


powershell 4.0

i want host powershell engine in application , have capability of using api of application in hosted powershell. read description of powershell class , members in documentation. in powershell.exe , powershell_ise.exe hosts can create variables, loops, launch static , instance methods of classes. can same through powershell class? can't find the examples it.

it simple attempt it:

using system;  using system.linq;  using system.management.automation;    namespace mypowershellapp {        class user {          public static string statichello() {              return "hello static method!";          }          public string instancehello() {              return "hello instance method!";          }      }        class program {          static void main(string[] args) {              using (powershell ps = powershell.create()) {                  ps.addcommand("[mypowershellapp.user]::statichello");                  // todo: here commandnotfoundexception exception                  foreach (psobject result in ps.invoke()) {                      console.writeline(result.members.first());                  }              }              console.writeline("press key exit...");              console.readkey();          }      }  }



you asking how write program in scripting forum.  recommend learning building samples in windows sdk under powershell hosting examples.  post questions how write nd understand programs in developers forums.

you can call custom classes powershell.  read al of "add-type" https://technet.microsoft.com/en-us/library/hh849914.aspx?f=255&mspperror=-2147217396


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS