I've got the following code (stripped down to mostly just logic), which gets AD user details.
Sometimes I get all properties back, but rarely. More often than not (95% of the time), the MemberOf value is missing. Very frequently Canononical Name, Last Logon Timestamp, Mail, and TargetAddress will also be missing. I always get back Name, SamAccountName, UPN, DN and SID. The properties names exist in the object, just not their corresponding values.
At first I thought it might be something with the session scope, but that doesn't seem to be the case (I've tested with toast messages outputting the object assigned to a temp variable before handing it off to the session). I don't get this issue if I test in the terminal, nor do I get it running scripts - so the service account is fine. It's only using the app.
Note: The code does a couple of 'sync-udelement' hops because there are other items being pulled back elsewhere in the full version.
$session:UserID = $null
$session:User = $null
$cache:UserProperties = @(
"Name",
"SamAccountName",
"UserPrincipalName",
"Enabled",
"CanonicalName",
"DistinguishedName",
"LastLogonTimestamp",
"SID",
"Mail",
"TargetAddress",
"MemberOf",
"ShowInAddressBook"
)
New-UDApp -Title "User Overview" -Content {
New-UDForm -Content {
New-UDTextbox -Id 'txtSearchQuery' -Label 'Enter User ID'
} -OnSubmit {
$session:UserID = $EventData.txtSearchQuery
Sync-UDElement -Id 'LoadUser'
}
New-UDDynamic -Id 'LoadUser' -Content {
if (-not [string]::IsNullOrWhiteSpace($session:UserID)) {
# Issue appears to be right at the 'get-aduser' call - property values are missing here
$session:User = Get-ADUser -Identity $session:UserID -Property $cache:UserProperties
Sync-UDElement -Id 'UserDetails'
}
}
New-UDDynamic -Id 'UserDetails' -LoadingComponent {
New-UDProgress -Circular
} -Content {
if ($session:User) {
# Splits the object into a name/value list
$Data = ($session:User | Select-Object -Property $cache:UserProperties).psobject.Properties.foreach({ [pscustomobject]@{Property=$_.Name; Value=$_.Value} })
$Columns = @(
New-UDTableColumn -Property Property -Title Property
New-UDTableColumn -Property Value -Title Value
)
New-UDTable -Data $Data -Columns $Columns
}
}
}