在 Powershell 中使用带有 -gt 的 EXO TotalItemSize - 对于某些邮箱大小不准确
Using EXO TotalItemSize with -gt in Powershell - inaccurate for some mailbox sizes
我的终止用户脚本中有一些代码,用于在转换为共享邮箱之前检查用户 365 邮箱的大小。这是一些客户的程序。如果邮箱大于 50GB,脚本应该通知管理员并且不要继续转换,否则它最终会在没有分配 365 许可证的情况下被删除。
$TotalItemSize = Get-MailboxStatistics $termUserPrincipalName | Format-Table TotalItemSize -hidetableheaders | Out-String
$Value = $TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")
If ($TotalItemSize -match "\((?<Size>.*) ")
{
$Value = $Matches.Size.Replace(",","")
}
If ($Value -gt 50gb)
{
write-host "Mailbox is greater than 50GB for $termUserPrincipalName"
}
else
{
write-host "Proceeding to convert mailbox ..."
Set-Mailbox $termUserPrincipalName -Type shared
}
该代码在大多数情况下都运行良好,但对于某些邮箱,它错误地将它们读取为大于 50GB,而实际上并非如此。我不知道为什么。
Here is my data in excel which for some reason pasted as an image.
只是对此的更新。
我一直在用这个,效果很好。
$TotalItemSize = Get-MailboxStatistics $UPN | Format-Table TotalItemSize -hidetableheaders | Out-String
$Value = $TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")
if ($TotalItemSize -match "\((?<Size>.*) "){
$Value = $Matches.Size.Replace(",","")
$TaotalItemSize = [int64]::Parse($Value)
}
if ($TotalItemSize -gt 50gb){
write-host "Mailbox is greater than 50GB for $UPN"
}
else{
write-host "Proceeding to convert to Shared Mailbox"
}
我的终止用户脚本中有一些代码,用于在转换为共享邮箱之前检查用户 365 邮箱的大小。这是一些客户的程序。如果邮箱大于 50GB,脚本应该通知管理员并且不要继续转换,否则它最终会在没有分配 365 许可证的情况下被删除。
$TotalItemSize = Get-MailboxStatistics $termUserPrincipalName | Format-Table TotalItemSize -hidetableheaders | Out-String
$Value = $TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")
If ($TotalItemSize -match "\((?<Size>.*) ")
{
$Value = $Matches.Size.Replace(",","")
}
If ($Value -gt 50gb)
{
write-host "Mailbox is greater than 50GB for $termUserPrincipalName"
}
else
{
write-host "Proceeding to convert mailbox ..."
Set-Mailbox $termUserPrincipalName -Type shared
}
该代码在大多数情况下都运行良好,但对于某些邮箱,它错误地将它们读取为大于 50GB,而实际上并非如此。我不知道为什么。
Here is my data in excel which for some reason pasted as an image.
只是对此的更新。 我一直在用这个,效果很好。
$TotalItemSize = Get-MailboxStatistics $UPN | Format-Table TotalItemSize -hidetableheaders | Out-String
$Value = $TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")
if ($TotalItemSize -match "\((?<Size>.*) "){
$Value = $Matches.Size.Replace(",","")
$TaotalItemSize = [int64]::Parse($Value)
}
if ($TotalItemSize -gt 50gb){
write-host "Mailbox is greater than 50GB for $UPN"
}
else{
write-host "Proceeding to convert to Shared Mailbox"
}