Product: PowerShell Universal
Version: 3.7.10
I have a UDForm working 100% as-is, but wanted to try and make one subtle change–I don’t want the UDTextbox to disappear when submitted. I have added a New-UDElement and Set-UDElement and the UDTextBox sticks around (great!) but updating the text box and clicking Submit fails–nothing happens with the UDElement/UDDynamic data. The only fix is to reload the entire page (not great). Is there something I’m missing or some other way to accomplish the desired outcome? Ideally the UDTextbox would persist still be able to update the username and re-submit the form. Code:
New-UDPage -Name 'Test Dynamic Form' -Content {
New-UDForm -Content {
New-UDTextbox -Id 'ADUsername' -Placeholder 'Enter AD username'
} -OnSubmit {
$UserName = $EventData.ADUsername.Trim()
If (-Not ([bool]([adsisearcher]"samaccountname=$UserName").FindOne()) ) {
Show-UDToast "ERROR: Unable to find [$UserName]" -MessageColor Red -Position center -Duration 5000
} Else {
Set-UDElement -Id 'TestElement' -Content {
New-UDDynamic -id "dyn_UserData" -Content {
$IconSuccess = New-UDIcon -Id "iconSuccess" -Icon CheckCircle -Size 2x -Color Green
$IconFailure = New-UDIcon -Id "iconFailure" -Icon Frown -Size 2x -Color Red
$Now = $([DateTime]::Now)
$UserProperties = 'Enabled','DistinguishedName','SamAccountname','LockedOut','AccountExpirationDate','PasswordExpired','memberof'
$UserData = Get-ADUser -Identity $UserName -Properties $UserProperties
New-UDList -SubHeader "Login Health for [$Username]. ($Now)" -Content {
Switch ($UserData.Enabled) {# Enabled Check
$false {
New-UDListItem -Label 'Account is disabled' -Icon $IconFailure
New-UDButton -Text "Enable $($UserData.SamAccountName)" -OnClick {
Enable-ADAccount $UserData.SamAccountname
sync-udelement -id "dyn_UserData"
}
}
$true {
New-UDListItem -Label 'Account is enabled' -Icon $IconSuccess
}
}
Switch ($UserData.AccountExpirationDate) {# Account Expired Check
{ $null -eq $_ } {
New-UDListItem -Label 'User account is not expired' -Icon $IconSuccess
}
{ $_ -gt $Now } {
New-UDListItem -Label "User account expires [$($UserData.AccountExpirationDate)]" -Icon $IconSuccess
}
{ $_ -lt $Now -and $null -ne $_ } {
New-UDListItem -Label "User account is expired. Expired [$($UserData.AccountExpirationDate)]" -Icon $IconFailure
New-UDDatePicker -Id 'dateExtensionDate' -Value (Get-Date -Format 'dd-MM-yyyy')
New-UDButton -Text "Extend $($UserData.SamAccountName)" -OnClick {
$Date = (Get-UDElement -Id 'dateExtensionDate').Value
Set-AdUser $UserData.SamAccountName -AccountExpirationDate $Date
}
}
}
Switch -Regex ($UserData.DistinguishedName) { # DistinguishedName Check
{ $_ -match 'OU=Bad' } {
New-UDListItem -Label 'User is located under "Bad" OU. Move object in AD and refresh' -Icon $IconFailure
Continue
}
{ $_ -notmatch 'OU=Good' } {
New-UDListItem -Label "User account is located in invalid OU [$_]. Move object in AD and refresh" -Icon $IconFailure
Continue
}
{ $_ -match "OU=Good" } {
New-UDListItem -Label 'User is in valid OU' -Icon $IconSuccess
}
}
Switch ($UserData.LockedOut) { # AD Lockout Check
$true {
New-UDListItem -Label 'Account is locked' -Icon $IconFailure
New-UDButton -Text "Unlock $Username" -OnClick {
Unlock-ADAccount $UserData.SamAccountname
sync-udelement -id "dyn_UserData"
}
}
$false {
New-UDListItem -Label 'Account is unlocked' -Icon $IconSuccess
}
}
switch ($UserData.PasswordExpired) {# Pasword Expired Check
$true {
New-UDListItem -Label 'Password has expired' -Icon $IconFailure -SubTitle 'User must change password'
}
$false {
New-UDListItem -Label 'Password is not expired' -Icon $IconSuccess
}
}
}
New-UDButton -Text 'Refresh User Data' -OnClick {
Sync-UDElement -id "dyn_UserData"
}
} -LoadingComponent {
New-UDProgress -Circular
}
}
}
}
New-UDElement -Id 'TestElement' -Tag 'div' # Added so form doesn't disappear upon submittal
} -Url '/TestDynamicForm'