SELECT Name,AccountEnabled,MailboxEnabled
FROM OpenExchangePSQuery(
POWERSHELL, '
#Imports the AD PS Module
Import-Module ActiveDirectory
#Gets the status of each AD account
$users = Get-ADUser -Filter *
foreach ($u in $users)
{
$name = $u.name
$IsEnabled = $u.enabled
$UPN = $u.userprincipalname
#Gets the Exchange mailboxes for each AD user.
$mailboxes = Get-Mailbox -RecipientTypeDetails "UserMailbox" | ?{$_.UserPrincipalName -eq "$UPN"}
#Get mailbox statistics for listed mailboxes
foreach ($mbx in $mailboxes)
{
$MailboxActive = $mbx.IsMailboxEnabled
#Creates a new result table to display the results of the script
foreach ($m in $mailboxactive)
{$Result = New-Object PSObject -Property @{
Name = $name
AccountEnabled = $IsEnabled
MailboxEnabled = $MailboxActive
}
$Result | select Name,AccountEnabled,MailboxEnabled
}
}
', POWERSHELL
)