Need some help in formatting the Column export result to remove the SMTP: & smtp: ?
Posted: Sun Sep 02, 2018 9:15 pm
Hi People,
I need some help with the Replace string operation to make sure the result does not contain the SMTP: and smtp: string?
The below script export the list of the Disabled AD account with their corresponding Exchange mailbox details:
However, the problem with the Export.CSV ProxyAddresses column output is the content of the column is like:
SMTP:First.Last@domain.com;First.Last@domain2.com;Alias1@domain.com
So how to get rid of that SMTP: string?
Thank you in advance.
I need some help with the Replace string operation to make sure the result does not contain the SMTP: and smtp: string?
The below script export the list of the Disabled AD account with their corresponding Exchange mailbox details:
Code: Select all
$filter = '(Enabled -eq $false) -and (homeMDB -ne "$null")'
$properties = @('homeMDB', 'mailNickName', 'mail', 'DisplayName', 'SamAccountName', 'ProxyAddresses')
$Allusers = (Get-ADUser -Filter $filter -Properties $properties |
ForEach-Object {
$MBSize = (Get-MailboxStatistics $_.SamAccountName).TotalItemSize.Value.ToMB()
$MBLastLogonTime = (Get-MailboxStatistics $_.SamAccountName).LastLogonTime
$MBLastLoggedOnUserAccount = ((Get-MailboxStatistics $_.SamAccountName).LastLoggedOnUserAccount)
$MBDisconnectDate = ((Get-MailboxStatistics $_.SamAccountName).DisconnectDate)
$MBSMTPAddresses = ($_.ProxyAddresses | Where-Object {$_ -like "*smtp:*" }).replace("smtp:","") -join ';'
New-Object -TypeName PSObject -Property @{
DisplayName = $_.DisplayName
mailNickName = $_.mailNickName
SamAccountName = $_.SamAccountName
mail = $_.mail
ProxyAddresses = $MBSMTPAddresses
homeMDB = (($_.homeMDB).split(',')[0]).split('=')[1]
MBytes = $MBSize
LastLogonTime = $MBLastLogonTime
LastLoggedOnUserAccount = $MBLastLoggedOnUserAccount
DisconnectDate = $MBDisconnectDate
}
}) | Sort-Object MBytes -Descending | Export-Csv "C:\Result.csv" -NoTypeInformation
SMTP:First.Last@domain.com;First.Last@domain2.com;Alias1@domain.com
So how to get rid of that SMTP: string?
Thank you in advance.