none
C# ASP.Net -- Powershell -- Adding item to multivalued property delays in background RRS feed

  • Question

  • I'm using the System.Management.Automation package to run Exchange PowerShell cmdlets from my C# code.  When I update a multivalued property (in this case, the EmailAddresses) on a user's Exchange mailbox, then immediately get the mailbox back, the multivalued property isn't always updated immediately, even though my Invoke() call has finished, so the PSObject returned doesn't have the updated data. 

    Here's the code:

    PowerShell shell = PowerShell.Create();
    shell.AddScript("Import-Module -Name \"" + exchangeModule + "\"");
    shell.Invoke();
    shell.AddScript("Set-Mailbox -Identity \"user1\" -EmailAddresses @{add=\"eum:59999;phone-context=Primary.ourdomain.local\"}");
    shell.Invoke();
    shell.AddScript("Get-Mailbox \"user1\"");
    ICollection<PSObject> results = shell.Invoke();

    I've noticed that this happens most when the multivalued property contains more than 3 or 4 objects.  However, when I do this directly in PowerShell, this problem disappears.  What could be causing it?

    • Moved by Bill_Stewart Tuesday, August 29, 2017 6:49 PM Move to more appropriate forum
    Tuesday, August 29, 2017 6:14 PM