Using Enabled Property in if Statement

Welcome Forums General PowerShell Q&A Using Enabled Property in if Statement

Viewing 2 reply threads
  • Author
    Posts
    • #186101
      Participant
      Topics: 1
      Replies: 2
      Points: 22
      Rank: Member

      Hello Guys first post I am righting a simple ps1 script to disable, set expiration, and move an ad account. Currently this works, however for betting confimation support. I would like add "if" statements to each process confirming the prior process. 

      So for instance after the account is disabled I would like to put an if the account is disabled then proceed to set expiration.

      So direct question is how can i confirm that the account is disabled before I continue to the next set of instructions.  Thank you for your insight I am fairly new to powershell hope this makes sense.

    • #186206
      Participant
      Topics: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      I'd recommend to use a little clearer or more descriptiv variable names. You use the variable name $DisabeledUser before the account is actually disabled. 😉

      Most Powershell cmdlets without any default output have a parameter -PassThru. This creates a object representing the treated input object. So for example:

      $Server = 'tewwvapwdc05.retail.sephoraus.com'
      $TreatedUser = Disable-ADAccount -Identity $RetailUser -Server $Server -PassThru
      If (-not ($TreatedUser.enabled)) {
          "$RetailUser successfully disabled"
      }

      ... of course instead of the output you can put some more command there.

      Additionally I'd recommend to use the parameter -Server for all the AD cmdlets. That ensures you work with the same object and not work with one AD object on one server and the next command tries to acces the same AD object but on another server.

    • #186326
      Participant
      Topics: 1
      Replies: 2
      Points: 22
      Rank: Member

      That is great info. I will read up on passthru and give it a shot. Thanks for the information Olaf. also thank you for the reccomends as well. I am always looking for great pointers for efficiency anc consitency.

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