Clear a flag in ADSI – For beginner

Welcome Forums General PowerShell Q&A Clear a flag in ADSI – For beginner

Viewing 5 reply threads
  • Author
    Posts
    • #210588
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      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.

    • #210594
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      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!

    • #210603
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      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:

      #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

       

    • #210615
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

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

    • #210654
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      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"

    • #210663
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      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!

Viewing 5 reply threads
  • You must be logged in to reply to this topic.