Hi All,
I want to use the below powershell command in c# and get the desired output.
Powershell script:
foreach($a in get-mailbox){get-activesyncdevicestatistics -mailbox $a.identity | Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={$a.displayname}}}
------------------------------------------------------------------------
I have made the code as below, but need your help to work on Select part with hash table. Please let me know, how I can include the "Select DeviceFriendlyName, Devicetype, DeviceUserAgent,@{Name="User Name";expression={$a.displayname}}}" in the below code.
----------------------------------------------------------------------------
C# code:
PowerShellpowershell = PowerShell.Create();
PSCommandcommand = newPSCommand();
command.AddCommand("Get-Mailbox");
command.AddCommand("where-object");
command.AddParameter("Filterscript", scriptBlock.Create("!$_.name.startswith(\"DiscoverySearchMailbox\")"));
powershell.Commands = command;
powershell.Runspace = CreateRunSpace.GetRunSpace();
varresult = powershell.Invoke();
PSCommandcommand1 = newPSCommand();
command1.AddCommand("write-output");
command1.AddParameter("InputObject", result);
command1.AddCommand("Foreach-Object");
command1.AddParameter("Process", ScriptBlock.Create("Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity"));
powershell.Commands = command1;
powershell.Runspace = CreateRunSpace.GetRunSpace();
var result1 = powershell.Invoke();