【发布时间】:2019-04-19 08:40:33
【问题描述】:
当我运行以下 PowerShell 脚本以获取未归类为共享邮箱的非活动 AD 用户帐户 Exchange 邮箱列表时。
脚本:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODMAIL01-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
$filter = '(Enabled -eq $false) -and (msExchRecipientTypeDetails -ne 4) -and (homeMDB -ne "$null")'
$properties = @('homeMDB', 'mailNickName', 'mail', 'DisplayName', 'SamAccountName', 'ProxyAddresses')
Get-ADUser -Filter $filter -Properties $properties |
ForEach-Object {
$stat = Get-MailboxStatistics $_.SamAccountName
$smtpAddresses = ($_.ProxyAddresses | Where-Object {$_ -like "*smtp:*" }) -replace 'smtp:'
New-Object -TypeName PSObject -Property ([ordered]@{
DisplayName = $_.DisplayName
mailNickName = $_.mailNickName
SamAccountName = $_.SamAccountName
mail = $_.mail
ProxyAddresses = $smtpAddresses -join ';'
HomeMDB = $_.homeMDB.Split(',=')[1]
MBytes = $stat.TotalItemSize.Value.ToMB()
LastLogonTime = $stat.LastLogonTime
LastLoggedOnUserAccount = $stat.SamAccountName
DisconnectDate = $stat.DisconnectDate
})
} |
Sort-Object MBytes -Descending |
Export-Csv C:\TEMP\Results.csv -NoTypeInformation
这是重复数千次的错误消息:
方法调用失败,因为 [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] 没有 包含一个名为“ToMB”的方法。在行:15 字符:5 + 新对象 -TypeName PSObject -Property ([ordered]@{ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : InvalidOperation: (ToMB:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
【问题讨论】:
标签: powershell scripting active-directory exchange-server windows-scripting