how to get value of account enabled from aduser

Welcome Forums General PowerShell Q&A how to get value of account enabled from aduser

Viewing 7 reply threads
  • Author
    Posts
    • #220500
      Participant
      Topics: 28
      Replies: 67
      Points: 375
      Rank: Contributor

      Hi I want to check if a useraccount in AD is enabled or disabled

      #Install-Module -name azuread
      Connect-AzureAD
      $Account = “user@mail.com”
      $value =”False”
      $accountEnabled =get-azureADUser -objectid $Account | select accountEnabled
      if ($accountEnabled -eq $value){
          Write-Host “please continue”
          }
          else {
          write-host “exit script”
       }

      when I run the above script it gives me as output “exit script”
      when I run $accountEnabled I get this as output
      AccountEnabled
      ————–
      False
      how do I capture the value “False” here?

      Paul
    • #221223
      Participant
      Topics: 3
      Replies: 324
      Points: 1,056
      Helping Hand
      Rank: Community Hero

      Expand it while saving to variable like this

      Select -expandproperty accountenabled
      

      or reference the property after storing as you did previously.

      $accountenabled.accountenabled
    • #221628
      Participant
      Topics: 28
      Replies: 67
      Points: 375
      Rank: Contributor

      Hi
      thanks for that, it still gives me “exit script” as output

      when I ask the content of $accountEnabled the value is False

      $accountEnabled =get-azureADUser -objectid $Account | select -ExpandProperty accountEnabled
      
      

      any thoughts on how to capture the $value =”False” correctly in the if statement?

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

      Since “accountEnabled” already is a boolean you can use this in your if statement:

      $Account = get-azureADUser -objectid 'user@mail.org'
      if ($Account.AccountEnabled) {
          Write-Host 'please continue'
      }
      else {
          write-host 'exit script'
      }
    • #221661
      Participant
      Topics: 28
      Replies: 67
      Points: 375
      Rank: Contributor

      @Olaf
      in this scenario the code will proceed when the account is enabled right? so If I want to change this then I would need to

      if(!($Account.accountEnabled)) {
      write-host “please continue”
      }
      else {
      
      write-host “exit script”
      
      }
      
    • #221673
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      Ah … yes. Right.

      Sorry I got this wrong … 😉

    • #221703
      Participant
      Topics: 28
      Replies: 67
      Points: 375
      Rank: Contributor

      no worries thanks for your help

    • #221919
      Participant
      Topics: 3
      Replies: 324
      Points: 1,056
      Helping Hand
      Rank: Community Hero

      when I run $accountEnabled I get this as output AccountEnabled ————– False how do I capture the value “False” here?

      You asked how to capture the value false. I gave you the exact answers, yet you say.

      when I ask the content of $accountEnabled the value is False PowerShell3 lines 1 2 3 $accountEnabled =get-azureADUser -objectid $Account | select -ExpandProperty accountEnabled any thoughts on how to capture the $value =”False” correctly in the if statement?

      Which is precisely what you just said  with “the content of $accountenabled is false”. What do you mean capture it as false correctly. What am I missing?

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