PowerShell Script to export mailboxes with state and description attribute

As you know, standard Get-Mailbox cmdlet don’t have stateorprovince and description properties.Just check with

[powershell] Get-Mailbox | Get-Member [/powershell]


Well then, what is the best way to get these properties within one single script?

In the script below, all users which has mailboxes, are exported with Organizational Unit, Display Name, State or Province, Description and Primary SMTP Address fields.

[powershell]import-module activedirectory
$exchangesunucular = Get-MailboxServer
$tumkullanicilar = @()
$tumkullanicilarexport = @()

foreach ($sunucu in $exchangesunucular)
$tumkullanicilar += Get-Mailbox -Server $sunucu
foreach ($kullanici in $tumkullanicilar)
$obj = new-object psObject
$info1 = get-mailbox -identity $kullanici.displayname | select PrimarySMTPAddress,Office, DistinguishedName
$tmp = [adsi](“LDAP://” + $info1.DistinguishedName)
$info2 = get-user -identity $kullanici.displayname | select distinguishedname,stateorprovince
$tmp2 = [adsi](“LDAP://” + $info2.DistinguishedName)

$obj |Add-Member -MemberType noteproperty -Name “Display Name” -Value $kullanici.DisplayName
$obj |Add-Member -MemberType noteproperty -Name “Description” -Value $tmp.description.value
$obj |Add-Member -MemberType noteproperty -Name “OU” -Value $kullanici.organizationalunit
$obj |Add-Member -MemberType noteproperty -Name “Alias” -Value $kullanici.alias
$obj |Add-Member -MemberType noteproperty -Name “SMTP Address” -Value $kullanici.PrimarySmtpAddress
$obj |Add-Member -MemberType noteproperty -Name “Database” -Value $kullanici.Database
$obj |Add-Member -MemberType noteproperty -Name “State” -Value $info2.stateorprovince

$tumkullanicilarexport += $obj

$tumkullanicilarexport |Export-Csv c:Export.csv –NoTypeInformation [/powershell]

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 86 = 93