how to get value of accountenabled

Welcome Forums General PowerShell Q&A how to get value of accountenabled

Viewing 2 reply threads
  • Author
    Posts
    • #220494
      Participant
      Topics: 30
      Replies: 74
      Points: 400
      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
    • #226257
      Participant
      Topics: 0
      Replies: 14
      Points: 175
      Helping Hand
      Rank: Participant

      Hello acer460527,

      On line #6 at the end before account enabled add -ExpandProperty and it will work:

      
      $accountEnabled=Get-AzureADUser -objectID $Account | select-object -ExpandProperty accountEnabled
      
      

      Hope that helps.

       

      • This reply was modified 3 weeks, 4 days ago by AndySvints.
    • #226290
      Participant
      Topics: 30
      Replies: 74
      Points: 400
      Rank: Contributor

      thanks Andy this works

      best regards

      Paul

       

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