how to get value of account enabled from aduser

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


#Install-Module -name azuread
$Account = ""
$value ="False"
$accountEnabled =get-azureADUser -objectid $Account | select accountEnabled
if ($accountEnabled -eq $value){
Write-Host "please continue"
else {
write-host "exit script"
[/pre] 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?

Expand it while saving to variable like this

Select -expandproperty accountenabled

or reference the property after storing as you did previously.


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?

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

$Account = get-azureADUser -objectid ‘’
if ($Account.AccountEnabled) {
Write-Host ‘please continue’
else {
write-host ‘exit script’

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”


Ah … yes. Right.

Sorry I got this wrong … :wink:

no worries thanks for your help

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

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?