2 Replies - 673 Views - Last Post: 04 August 2016 - 05:33 AM Rate Topic: -----

#1 kewlkevkev   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 03-August 16

Executing Powershell function (from ps1 file) from C# code.

Posted 03 August 2016 - 12:10 PM

I am trying to execute a powershell function from my C# code but when I call
Invoke()
I get a
CommandNotFoundException
. My Code is as follows:
ps = PowerShell.Create();
ps.AddScript("UMA.ps1");
ps.Invoke();
ps.AddCommand("uar");
ps.AddArgument(outputDir + @"\out.csv");
ps.Invoke();


The script UMA.ps1 contains a function called "uar" and is copied to my build directory.

What is causing this error?

Is This A Good Question/Topic? 0
  • +

Replies To: Executing Powershell function (from ps1 file) from C# code.

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,989
  • Joined: 05-May 12

Re: Executing Powershell function (from ps1 file) from C# code.

Posted 03 August 2016 - 06:51 PM

What do the details fields of the exception say?
Was This Post Helpful? 0
  • +
  • -

#3 kewlkevkev   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 03-August 16

Re: Executing Powershell function (from ps1 file) from C# code.

Posted 04 August 2016 - 05:33 AM

Sorry about this, It turns out the problem was being caused by execution of scripts only being enabled in x64 powershell and not x86.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1