//Build// Code on Weekend // Reach out if any one want to share cool FIM/MIM, IAM related Project. Mail : Any.Singha@gmail.com
Sunday, 5 April 2015
Saturday, 4 April 2015
Calling Powershell from C#.
Calling Powershell from C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Provider;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
namespace PowerShell_Call
{
class Program
{
public static string name(string args)
{
using (PowerShell powershell = PowerShell.Create().AddCommand("Get-Process").AddArgument(args))
{
foreach (PSObject result in powershell.Invoke())
{
return result.Members["id"].Value.ToString();
}
}
return "";
}
static void Main(string[] args)
{
string x = "apnmcp";
string v=name(x);
Console.WriteLine("The value is {0}", v);
Console.ReadLine();
}
}
}
In the solution explorer, add a project reference to the System.Management.Automation. I always found this in
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Provider;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
namespace PowerShell_Call
{
class Program
{
public static string name(string args)
{
using (PowerShell powershell = PowerShell.Create().AddCommand("Get-Process").AddArgument(args))
{
foreach (PSObject result in powershell.Invoke())
{
return result.Members["id"].Value.ToString();
}
}
return "";
}
static void Main(string[] args)
{
string x = "apnmcp";
string v=name(x);
Console.WriteLine("The value is {0}", v);
Console.ReadLine();
}
}
}
Output :
Console Application
Powershell Output.
Subscribe to:
Posts (Atom)
-
Note : This series is for the Beginner and trouble shooting the Error With Sync Engine, Based on Test Lab, Highly advice do not do Full Syn...
-
This article can be refer as reference only, how can you build your first Management Agent connect to Service Now. The samples code show...
-
Error “Does not have a parent object in Management agent.” When I run the Delta Sycs for FIM MA, I started getting the error Sync-r...