在修复 PowerShell 格式化列导出结果以删除 SMTP: & smtp: 方面需要一些帮助吗?

Need some assistance in fixing the PowerShell formatting the Column export result to remove the SMTP: & smtp:?

我想使用替换字符串操作来确保结果不包含 SMTP: 和 smtp: 字符串。

以下脚本导出禁用的 AD 帐户列表及其相应的 Exchange 邮箱详细信息:

$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

Export.CSV ProxyAddresses 列输出的问题是该列的内容如下:

SMTP:First.Last@domain.com;First.Last@domain2.com;Alias1@domain.com

注意 SMTP:email.user@domain.com 仍在 ProxyAddresses 列中 Result.CSV 所有小写的都没有显示.

当您使用 class 方法时 .Replace() 区分大小写 。因此,您必须将 .Replace('smtp:','') 的条件更改为大写 .Replace('SMTP:','') 或使用 Powershell 的 -replace 运算符, 不区分大小写 .

$MBSMTPAddresses = (($_.ProxyAddresses | Where-Object {$_ -like "*smtp:*" }) -replace 'smtp:') -join ';'