I am playing around with WPF and powershell project for a tool and some learning. I have built a screen which allows you to display user information. I have added checkboxes next to each textbox so that if you edit a field then click the button it will change that section.
The issue i have is i cannot get it to work based on the selection. I have the below which works in the way it changes all fields regardless of the selection. I have played around with a few combinations but none seem to give the desired effect.
function UpdateUserInfoClick
{
param($sender, $e)
# prepare table
$userUpdateData = @{
Identity = $UserSearchName.text
Server = $UserSearchDomainSelect.text
Credential = $ADMCreds
GivenName = $USFN.Text
SurName = $USLN.Text
DisplayName = $USDN.Text
Description = $USDesc.Text
Confirm = $false
}
# populate entry values associated with checked checkboxes
if ($USFNCB.IsChecked = $true) {
$userUpdateData['GivenName'] = $USFN.Text
}
if ($USLNCB.IsChecked = $true) {
$userUpdateData['SurName'] = $USLN.Text
}
if ($USDNCB.IsChecked = $true) {
$userUpdateData['DisplayName'] = $USDN.Text
}
if ($USDescCB.IsChecked = $true) {
$userUpdateData['Description'] = $USDesc.Text
}
# decide on target server based on selected domain
if ($UserSearchDomainSelect.text -eq "Domain1") {
$userUpdateData['Server'] = 'Domain1.com'
}
elseif ($UserSearchDomainSelect.text -eq "Domain2") {
$userUpdateData['Server'] = 'Domain2.com'
}
elseif ($UserSearchDomainSelect.text -eq "Domain3.com") {
$userUpdateData['Server'] = 'Domain3.com'
}
else {
throw 'unexpected domain selection, cannot map to domain controller'
}
if ($userUpdateData.Count -gt 1) {
# at least 1 updated property was checked, let's update the backend
Set-ADUser @userUpdateData
}
}
The xaml code for one of the checkboxes
<CheckBox x:Name="USFNCB" Content="" HorizontalAlignment="Left" Margin="461,148,0,0" VerticalAlignment="Top" Height="20" Width="20" IsChecked="False"/>
Not sure if there is some more definition need for the states in the Xaml or the the set-eventhandlers
?
Thanks