I have a form I am building that runs 1 of 2 Exchange cmdlets based on user input. The 1st cmdlet is a simple Get-Mailbox and this usually completes in under 5 seconds. The 2nd cmdlet is Get-Mailbox -ResultSet unlimited and this usually takes up to 10 minutes to complete. The problem I have is that the 2nd command never updates my grid with data. It just continues to show a progress bar flashing across the grid. I ran the code directly within powershell and i get the correct data back so I know the syntax is correct. What can I change to make my grid update when executing long running endpoints?
My code:
New-UDInput -Title "Search Criteria" -Content {
New-UDInputField -Type 'textbox' -Name RecipientEmail -Placeholder 'Recipient Email Address (Seperate multiple addresses using semi-colon (;) / Leave blank to search all mailboxes)'
New-UDInputField -Type 'textbox' -Name SenderEmail -Placeholder 'Sender Email Address'
New-UDInputField -Type 'textbox' -Name AttachmentName -Placeholder 'Attachment Name'
New-UDInputField -Type 'textbox' -Name Keywords -Placeholder 'Keywords'
New-UDInputField -Type 'date' -Name StartDate -Placeholder 'Start Date'
New-UDInputField -Type 'date' -Name EndDate -Placeholder 'End Date'
} -Endpoint {
param($RecipientEmail, $SenderEmail, $AttachmentName, $Keywords, $StartDate, $EndDate)
Set-UDElement -Id "emailsearchresults" -Content {
New-UDGrid -Title "Search Results" -Headers @("Name", "Item Count", "Size", "Success") -Properties @("Name", "ItemCount", "Size", "Success") -Endpoint {
$RecipientList = @()
$SearchResults = @()
#Use this SearchQuery for testing.
$SearchQuery = "Subject:'I/O problems' AND received:11/08/2019"
if($RecipientEmail -like '*@*.*'){
$RecipientList = $RecipientEmail.Split(';').Trim()
foreach($Recipient in $RecipientList){
$SearchResults += Get-Mailbox $Recipient | Search-Mailbox -SearchQuery $SearchQuery -DoNotIncludeArchive -EstimateResultOnly | Select-Object Identity, ResultItemsCount, ResultItemsSize, Success | Where-Object { $_.ResultItemsCount -gt 0 }
}
}
else{
$SearchResults += Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery $SearchQuery -DoNotIncludeArchive -EstimateResultOnly | Select-Object Identity, ResultItemsCount, ResultItemsSize, Success | Where-Object { $_.ResultItemsCount -gt 0 }
}
$SearchResults | ForEach-Object {
[PSCustomObject]@{
Name = $_.Identity.Substring($_.Identity.LastIndexOf('/')+1)
ItemCount = $_.ResultItemsCount
Size = $_.ResultItemsSize
Success = $_.Success
}
} | Out-UDGridData
}
}
}
New-UDRow -Columns {
New-UDColumn -Size 12 {
New-UDElement -Tag "div" -Id "emailsearchresults"
}
}