I need to make an application which will run Power-Shell and run command Get-Dedupjob, but I received the following error:
the term "Get-Dedupjob" is not recognized as the name of a cmdlet, function, script file, or operable program.
Although mentioned command works properly when I run this in power-shell (show deduplication jobs).
I suppose that problem could be that program doesn't run command as administrator. Is there some solution ho to run this as admin? Or where could be the problem?
private void button5_Click(object sender, EventArgs e)
{
// Get-Dedupjob
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Get-Dedupjob");
// execute the script
Collection<PSObject> results = pipeline.Invoke();
// close the runspace
runspace.Close();
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
textBox1.Text = Convert.ToString(stringBuilder);
}