I’m trying to query a list of users in my O365/AzureAD subscription and display them in a grid. I have an AAD account with MFA disabled, and can pass in creds from a PS console to query the users. But when I try to use that as an Endpoint within a UDCard it throws a weird error.
Code example:
New-UDCard -Title “Azure AD Users” -Endpoint {
$ux = “username@domain.com ”
$pw = ConvertTo-SecureString “password” -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | Select DisplayName,Department,Title,City,State | Out-UDGridData
}
Error message shown in the card:
Minified React error #31 ; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20{draw%2C%20recordsTotal%2C%20data%2C%20recordsFiltered}&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
adam
August 22, 2019, 5:01pm
2
This is usually an issue with formatting on the JavaScript side of things but you can fix it within your script be trying to simplify the values going to the grid as much as possible. I’ve seen issues with Select-Object
Try this instead:
New-UDCard -Title “Azure AD Users” -Endpoint {
$ux = "username@domain.com"
$pw = ConvertTo-SecureString “password” -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | ForEach-Object {
[PSCustomObject]@{
DisplayName = $_.DisplayName.ToString(),
Department = $_.Department.ToString(),
Title = $_.Title.ToString(),
City = $_.City.ToString() ,
State = $_.State.ToString() | Out-UDGridData
}
}
I know this is a little long winded but should work. It’s something we could improve in UD so it’s not necessary but hopefully this works for now.
That looks good, but some of the closing braces are off a bit. I fixed that and ran it, but getting “You cannot call a method on a null-valued expression” in the card.
Adjusted code:
$Page = New-UDPage -Name "Page1" -Icon link -Content {
New-UDCard -Title “Azure AD Users” -Endpoint {
$ux = 'user@domain.com'
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | ForEach-Object {
[PSCustomObject]@{
DisplayName = $_.DisplayName.ToString()
Department = $_.Department.ToString()
Title = $_.Title.ToString()
City = $_.City.ToString()
State = $_.State.ToString()
} | Out-UDGridData
}
}
}
If I highlight the code in VSCode or ISE and run it (F8) it works fine.
adam
August 22, 2019, 7:10pm
4
Maybe try casting to string rather than ToString because something is null.
$Page = New-UDPage -Name "Page1" -Icon link -Content {
New-UDCard -Title “Azure AD Users” -Endpoint {
$ux = 'user@domain.com'
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | ForEach-Object {
[PSCustomObject]@{
DisplayName = [string]$_.DisplayName
Department = [string]$_.Department
Title = [string]$_.Title
City = [string]$_.City
State = [string]$_.State
} | Out-UDGridData
}
}
}
Dang it. I feel like I’m really close, but still not there. Here’s the complete script, and output below that…
$Dashboard = New-UDDashboard -Title "AzureAD Users" -Content {
New-UDCard -Title “Azure AD Users” -Endpoint {
$ux = 'user@domain.com'
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | ForEach-Object {
[PSCustomObject]@{
DisplayName = [string]$_.DisplayName
Department = [string]$_.Department
Title = [string]$_.Title
City = [string]$_.City
State = [string]$_.State
} | Out-UDGridData
}
}
}
Start-UDDashboard -Dashboard $Dashboard -Port 8081
Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20%7Bdraw%2C%20recordsTotal%2C%20data%2C%20recordsFiltered%7D&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
adam
August 22, 2019, 7:42pm
6
Ah! I see the issue.
Try using New-UDGrid rather than New-UDCard.
$Dashboard = New-UDDashboard -Title "AzureAD Users" -Content {
New-UDGrid -Title “Azure AD Users” -Endpoint {
$ux = 'user@domain.com'
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | ForEach-Object {
[PSCustomObject]@{
DisplayName = [string]$_.DisplayName
Department = [string]$_.Department
Title = [string]$_.Title
City = [string]$_.City
State = [string]$_.State
}
} | Out-UDGridData
}
}
Start-UDDashboard -Dashboard $Dashboard -Port 8081
Honestly, I wonder if your first set of code would have worked too. Totally over looked this.
New-UDGrid -Title “Azure AD Users” -Endpoint {
$ux = "username@domain.com"
$pw = ConvertTo-SecureString “password” -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $ux, $pw
Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
Get-MsolUser -All | Select DisplayName,Department,Title,City,State | Out-UDGridData
}
OMFG. So, the first example (pscustomobject) works, sort of, but only displays the last item in the array. The second works fine. I feel 100 lbs lighter. Thank you!
So as a follow-up, my pages for users, devices and groups are working great. Here’s a link to the latest version I’m using… https://github.com/Skatterbrainz/ud-cmwt/blob/master/pages/aadusers.ps1