how to get value of account enabled from aduser

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

[pre]

#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"
}
[/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?
Paul

Expand it while saving to variable like this

Select -expandproperty accountenabled

or reference the property after storing as you did previously.

$accountenabled.accountenabled

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

when I ask the content of $accountEnabled the value is False
[pre]
$accountEnabled =get-azureADUser -objectid $Account | select -ExpandProperty accountEnabled

[/pre]

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 ‘user@mail.org’
if ($Account.AccountEnabled) {
Write-Host ‘please continue’
}
else {
write-host ‘exit script’
}

@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
[pre]
if(!($Account.accountEnabled)) {
write-host “please continue”
}
else {

write-host “exit script”

}
[/pre]

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?