Clear a flag in ADSI - For beginner

Hello everyone,

I’m just getting into learning more about powershell and the second project I have seems simple enough, but I can’t find the command to ‘clear’ the flag in ADSI.

The end goal is to have a prompt where someone can type in a username and it hit up ADSI to clear one flag from the account properties. If someone has a template I can use, I can expand off of it from there and fill in other flags and domain options I would really appreciate it.

If this is more difficult than I’m anticipating though, just let me know! I may have bitten off more than I can chew.

I think your description is a little vague. What “flag” would you like to “clear”? What ahve you tried already? You should search the internet and this forum for examples - there are thousands. If already have code you’ve got stuck with please share that code and we can try to help you.
Please read the instructions for this forum contained in the very first post of this forum: Read Me Before Posting! You’ll be Glad You Did!

Thanks for the reply!

Unfortunately the field name is proprietary so most of my search results are skewed, but it would be similar to the “homePhone” field in ADSI. There is a ‘clear’ button to remove any value set. Typically the field is a true, false, or <not set>. I just can’t find the command to say Clear to put it as the <not set> value.

For example I’ve got this. It’s not super complex, but I’m just missing one piece. Sorry if this is a dumb question:

[pre]#This part shows the current account info
Get-ADUser -identity USERNAME -properties Name,FLAG | Select-Object -property Name,FLAG
#This part should be what sets it to <not set>
Set-ADUser USERNAME -identity USERNAME -FLAG ???
#This confirms the change
Get-ADUser -identity USERNAME -properties Name,FLAG | Select-Object -property Name,FLAG[/pre]

 

You may (re-)read the complete help for Set-ADUser. The cmdlet has a parameter -Clear. :wink: Another option you could try would be to “set” it to $NULL.

If the attributes you are needing are custom, this has worked for me in the past.

$User = Get-ADUser -Identity jdoe -Properties yourFlagAttributeName
Set-ADUser –Identity $User -Clear “yourFlagAttributeName”

It worked like a charm guys.

I had misunderstood the book I was reading over and took the -clear as a statement rather than a command so the errors didn’t make sense. After I saw it written out from you guys it made perfect sense.

Thanks for your help!