Invoke-PSUScript from within a dashboard has very weird logging output
Product: PowerShell Universal Version: 5.3
I have the following page in my app:
New-UDPage -Url '/AddSharedMailboxPermissions' -Name "Add Shared Mailbox Permissions" -Content {
write-host '----------------------'
New-UDForm -Content {
New-UDTextbox -Id 'MailboxEmailAddress' -Label 'Mailbox Name'
New-UDTextbox -Id 'useridentities' -Label 'User Name'
New-UDCheckBox -id 'NoAutoMapping' -Label 'NoAutoMapping'
} -OnSubmit {
try
{
# Retrieve values from form elements
$MailboxEmailAddress = (Get-UDElement -Id 'MailboxEmailAddress').Value
$useridentities = (Get-UDElement -Id 'useridentities').Value.Split(',') | ForEach-Object { $_.Trim() } # Split comma-separated users and trim whitespace
$NoAutoMapping = (Get-UDElement -Id 'NoAutoMapping').Value
Write-Verbose "MailboxEmailAddress: $MailboxEmailAddress" -Verbose
Write-Verbose "useridentities: $($useridentities -join ',')" -Verbose
Write-Verbose "NoAutoMapping: $NoAutoMapping" -Verbose
$Script = Get-PSUScript -Name 'Add-Mailboxpermissions.ps1' -TrustCertificate
# Construct the hashtable for parameters
$Parameters = @{
MailboxEmailAddress = $MailboxEmailAddress
useridentities = $useridentities #Corrected name Users to match the ID
NoAutoMapping = $NoAutoMapping
}
$ScriptOutput = Invoke-PSUScript -Script $Script -Wait -TrustCertificate -Parameters $Parameters -Verbose
# $ScriptOutput | out-string | write-host
New-UDDynamic -Id 'dynamic3' -Content {
New-UDDataGrid -LoadRows {
$ScriptOutput | Out-UDDataGridData -Context $EventData
} -Columns @(
New-UDDataGridColumn -Field 'User' -Title 'User'
New-UDDataGridColumn -Field 'AccessRights' -Title 'AccessRights'
) -Pagination -PageSize 50 -RowsPerPageOptions @(10, 25, 50, 100) -AutoSizeColumns $true -DefaultSortColumn 'User' -DefaultSortDirection desc
}
}
catch
{
Write-host "Error: $($_.Exception.Message)"
Write-host $_.Exception.ToString()
New-UDTypography -Text "Error: $($_.Exception.Message)"
}
}
}
In the script, it goes like this:
[CmdletBinding()]
param (
[parameter(Mandatory = $True, Position = 0)]
[string]
$MailboxEmailAddress,
[parameter(Mandatory = $True, Position = 1)]
[string[]]
$useridentities,
[parameter(Mandatory = $False, Position = 2)]
[switch]$NoAutoMapping
)
write-host 'I made it here.'
import-module "C:\ProgramData\UniversalAutomation\Repository\Modules\ExchangeOnlineManagement\3.3.0\ExchangeOnlineManagement.psd1" | out-null
$exchangeSessions = Get-PSSession | Where-Object {
$_.ConfigurationName -eq "Microsoft.Exchange" -and
$_.Name -like "ExchangeOnline*"
}
$exchangeSessions | out-string | write-host
$MyCredential = $Secret:MySecret
Connect-ExchangeOnline -Credential $MyCredential -ErrorAction Stop -ShowBanner:$false
$EmailRegex = '^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$'
$counter = $null # Keeps track of processed records.
if (-not(Get-mailbox $MailboxEmailAddress -erroraction SilentlyContinue))
{
Write-Host '[-] Mailbox not found, wait for synchronisation (if already created, otherwise use Exchangetool to create mailbox and await replication (30 min)).' -ForegroundColor Red
break
}
return Get-MailboxPermission -Identity $MailboxEmailAddress
The log of the script, is how it should be:
But, the log of the application goes bananas:
It shows the text i made it here 5 times, This happens to be the amount of records given back by my request for permissions.
Can anyone please explain me why? In this particular case it is not an issue but with the full code, it does the same with removing sessions etc.
bbad9e604ed7931b2209547d6269d892d8db1f57.png
e6989c0448837bb3c64dcd08f0654e746e905402.png
I have experienced this to but even on v4.
I would love to get this addressed as well.
Ah, if that is the case, I’ll make a issue for it in Github.