dimanche 15 mars 2015

Using Powershell into C# to find out installed windows Features on WindowsServer2012

I am trying to fetch the Installed Windows Features using powershell in C# code.But unable to get them.The code I am writing is:


private void button1_Click(object sender, EventArgs e) { Runspace run = RunspaceFactory.CreateRunspace(); run.Open();



PowerShell power = PowerShell.Create();
power.Runspace = run;

power.AddScript(" $d = get-date; $s = 'Hi How are you ?'; $name='mukul'; $get=(Get-WindowsFeature -name File-Services).Installed; " +
"$d; $s; $name; $get");
foreach (PSObject result in power.Invoke())
{

MessageBox.Show(result.BaseObject.ToString() + "\n");


}


}


Till $name it is working fine but giving null reference exception at $get.Please help.


Aucun commentaire:

Enregistrer un commentaire