Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Powershell in C# | Requesting help on foreach loop.

$
0
0

Hi All,

Powershell Script :

ForEach ($Mailbox in Get-Mailbox) {Get-ActiveSyncDeviceStatistics -Mailbox

$Mailbox.Identity –ErrorAction SilentlyContinue | Select DeviceFriendlyName, Devicetype, DeviceUserAgent |

ForEach-Object { $_ | Add-Member –MemberType NoteProperty -Name "MailboxIdentity" -value $Mailbox

}}

I managed to go upto,

PowerShell powershell =PowerShell.Create();

PSCommand command =newPSCommand();

command.AddCommand(

"Get-Mailbox");

command.AddCommand(

"where-object");

command.AddParameter(

"Filterscript",ScriptBlock.Create("!$_.name.startswith(\"DiscoverySearchMailbox\")"));

powershell.Commands = command;

powershell.Runspace =CreateRunSpace.GetRunSpace();

var result = powershell.Invoke();

 

PSCommand command1 =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();I'm stuck at 2nd foreach loop to add-member while adding the output of get-mailbox. Appreciate your help and suggestions. Thank you.


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>