I am wondering if there is a way to toggle a UserAccountControl flag on or off despite the other flags' states. For example, let's say we have a configuration like the following:
How would I only toggle the 'Password never expires' flag to true despite the current $user.UserFlags.value
?
When all of the flags are toggled off, the $user.UserFlags.value
is 513. When only the 'Password never expires' flag is toggled, the $user.UserFlags.value
is 66049.
As you can imagine, there are a range of numbers that the $user.UserFlags.value
can reflect for different configurations as mentioned in the following article:
How to use the UserAccountControl flags to manipulate user account properties
I feel like I can come up with a solution using bit-wise manipulation with masks but need some guidance. My end goal is to write a Power Shell script to toggle this value on no matter what the current configuration may be.
Any suggestions?