Product: PowerShell Universal
Version: 1.4.6 (free license)
I have a script test.ps1
with the following code:
param($user)
$MyCredential = $Secret:MySecret
Connect-ExchangeOnline -Credential $MyCredential
$MailboxPermissions = Get-EXOMailboxPermission $user
IF ($MailboxPermissions) { return $MailboxPermissions }else { return 'Not found'}
Write-output "reached end of code."
Next, I’ve an App with the following code:
New-UDDashboard -Title 'Delegation tool POC' -Content {
New-UDForm -Content {
New-UDTextbox -id 'txtMailAddress' -Value 'My pretty room' -FullWidth
} -OnSubmit {
$value = (Get-UDElement -Id 'txtMailAddress').Value
Invoke-PSUScript -Name 'test.ps1' -user $value | Tee-Object -Variable job | Wait-PSUJob
# $data = Get-PSUJobPipelineOutput -JobId $job.ID
# $data = Get-PSUJobOutput -JobId $job.ID
$data = Get-PSUJobPipelineOutput -JobId $job.Id
if($data -notmatch 'Not found'){
Show-UDToast -Message "$($data)"
#$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $data | % {$_.User,$_.AccessRights} } -Attributes @{
$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $data | select * } -Attributes @{
style = @{
color = 'DarkGreen'
}
}
$div
}else{
Show-UDToast -Message "User $($value) not found."
$string = "User $($value) not found."
$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $string } -Attributes @{
style = @{
color = 'DarkRed'
}
}
$div
}
}
}
Now the script test.ps1
gives me a PScustomObject in the pipeline.
For the life of me I can’t figure out how to use that info in my App
.
For instance, how do i display it in a table? Or only use a few properties of my PsCustomObject?
The only thing that works is : #$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $data | % {$_.User,$_.AccessRights} }
But that doesn’t give me much control.
I’ve tried :
$Users = ForEach-Object -InputObject $DATA{
[PSCustomObject]@{
Name = $_.User
}
}
Show-UDToast -Message "$($users)"
#$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $data | % {$_.User,$_.AccessRights} } -Attributes @{
$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { $users } -Attributes @{
Also tried with a normal foreach
.
$data = Get-PSUJobPipelineOutput -JobId $job.Id
if($data -notmatch 'Not found'){
$users = $data | % { $_ }
Show-UDToast -Message "$($users)"
$div = New-UDElement -Tag 'div' -Id 'outputDiv' -Content { foreach ($user in $users) {@($user.User + ' ' + $user.AccessRights + "`t" )} } -Attributes @{
style = @{
color = 'DarkGreen'
}
}
$div
This works but now i have the issue everything is stuck on one line.
Getting closer though.
Edit 55:
New-UDTable -Id ‘TestTable2’ -Data $users -Title ‘Test’ -Dense
That is a nice discovery. Only problem left now is
Edit 56
$data = Get-PSUJobPipelineOutput -JobId $job.Id
if($data -notmatch 'Not found'){
# $users = $data.accessrights | % { $_ }
$users = $data | Select-Object Identity, User, AccessRights |
ForEach-Object {
[PSCustomObject]@{
Identity = $_.Identity
Name = $_.User
permissions = $_.AccessRights.Split(',') | out-string
}
}
New-UDTable -Id 'TestTable2' -Data ($users ) -Title 'Test' -Dense
This seems to be working.
Is this the best way to work with data coming from a script?