c# - Saving Powershell command output to listbox -
trying write gui program using c#.
i need execute powershell commands (like get-contentfilterphrase) , add output list box. able right (collection) in first line of listbox.
could describe how right, please.
here's 1 of attempts:
var rulelist = new list<string>(); var rsconfig = runspaceconfiguration.create(); using (var myrunspace = runspacefactory.createrunspace(rsconfig)) { pssnapinexception snapinexception = null; var info = rsconfig.addpssnapin("microsoft.exchange.management.powershell.e2010", out snapinexception); myrunspace.open(); using (var ps = powershell.create()) { ps.addscript("get-contentfilterphrase | where-object {$_.influence -match 'badword'}| format-table -property phrase"); var results = ps.invoke(); foreach (var result in results) { rulelist.add(result.tostring()); } } listbox1.items.add(rulelist); }
Comments
Post a Comment