Powershell command to find disabled AD accounts with active mailboxes and specific AD description
I am looking for a command to run in Powershell that will find all disabled AD accounts with active mailboxes and specific text thread in the AD description field. Below is what I have so far which will find the disabled AD user accounts with active
mailboxes:
$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match AccountDisabled -and $_.isLinked -match false -and $_.isResource -match false}
If possible, what parameters would I need to add to the line above to also find those disabled accounts with active mailboxes that also contain as specific word (example: "test") in the AD description?
Please contact me if you have any questions.
Thank you.
August 16th, 2012 2:38pm
On Thu, 16 Aug 2012 18:33:34 +0000, jsadmin wrote:
>
>
>I am looking for a command to run in Powershell that will find all disabled AD accounts with active mailboxes and specific text thread in the AD description field. Below is what I have so far which will find the disabled AD user accounts with active mailboxes:
>
>$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match AccountDisabled -and $_.isLinked -match false -and $_.isResource -match false}
>
>If possible, what parameters would I need to add to the line above to also find those disabled accounts with active mailboxes that also contain as specific word (example: "test") in the AD description?
>
>Please contact me if you have any questions.
You won't be able to get the description property with any Exchange
2007 cmdlets.
To get the description property use ADSI:
$desc = $null
$uadsi = [ADSI]"LDAP:$($_.distinguishedname)"
if ($uadsi.psbase.properties.propertynames -contains 'description')
{
$desc = $uadsi.psbase.properties.description[0]
}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 6:15pm
On Thu, 16 Aug 2012 18:33:34 +0000, jsadmin wrote:
>
>
>I am looking for a command to run in Powershell that will find all disabled AD accounts with active mailboxes and specific text thread in the AD description field. Below is what I have so far which will find the disabled AD user accounts with active mailboxes:
>
>$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match AccountDisabled -and $_.isLinked -match false -and $_.isResource -match false}
>
>If possible, what parameters would I need to add to the line above to also find those disabled accounts with active mailboxes that also contain as specific word (example: "test") in the AD description?
>
>Please contact me if you have any questions.
You won't be able to get the description property with any Exchange
2007 cmdlets.
To get the description property use ADSI:
$desc = $null
$uadsi = [ADSI]"LDAP:$($_.distinguishedname)"
if ($uadsi.psbase.properties.propertynames -contains 'description')
{
$desc = $uadsi.psbase.properties.description[0]
}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
August 16th, 2012 6:20pm
On Thu, 16 Aug 2012 22:15:44 +0000, Rich Matheisen [MVP] wrote:
>On Thu, 16 Aug 2012 18:33:34 +0000, jsadmin wrote: > > >I am looking for a command to run in Powershell that will find all disabled AD accounts with active mailboxes and specific text thread in the AD description field. Below is what I have so far which
will find the disabled AD user accounts with active mailboxes: > >$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match AccountDisabled -and $_.isLinked -match false -and $_.isResource -match false} > >If possible, what parameters
would I need to add to the line above to also find those disabled accounts with active mailboxes that also contain as specific word (example: "test") in the AD description? > >Please contact me if you have any questions. You won't be able to get the description
property with any Exchange 2007 cmdlets. To get the description property use ADSI: $desc = $null $uadsi = [ADSI]"LDAP:$($_.distinguishedname)" if ($uadsi.psbase.properties.propertynames -contains
>'description') { $desc = $uadsi.psbase.properties.description[0] } --- Rich Matheisen MCSE+I, Exchange MVP
>--- Rich Matheisen MCSE+I, Exchange MVP
That should be:
[ADSI]"LDAP://$($_.distinguishedname)"
The "//" was missing.
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 9:32pm
On Thu, 16 Aug 2012 22:15:44 +0000, Rich Matheisen [MVP] wrote:
>On Thu, 16 Aug 2012 18:33:34 +0000, jsadmin wrote: > > >I am looking for a command to run in Powershell that will find all disabled AD accounts with active mailboxes and specific text thread in the AD description field. Below is what I have so far which
will find the disabled AD user accounts with active mailboxes: > >$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match AccountDisabled -and $_.isLinked -match false -and $_.isResource -match false} > >If possible, what parameters
would I need to add to the line above to also find those disabled accounts with active mailboxes that also contain as specific word (example: "test") in the AD description? > >Please contact me if you have any questions. You won't be able to get the description
property with any Exchange 2007 cmdlets. To get the description property use ADSI: $desc = $null $uadsi = [ADSI]"LDAP:$($_.distinguishedname)" if ($uadsi.psbase.properties.propertynames -contains
>'description') { $desc = $uadsi.psbase.properties.description[0] } --- Rich Matheisen MCSE+I, Exchange MVP
>--- Rich Matheisen MCSE+I, Exchange MVP
That should be:
[ADSI]"LDAP://$($_.distinguishedname)"
The "//" was missing.
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
August 16th, 2012 9:37pm