Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Exchange将MailboxFolderStatistics FolderSize设置为MB_Powershell_Exchange Server_Powershell Remoting - Fatal编程技术网

Powershell Exchange将MailboxFolderStatistics FolderSize设置为MB

Powershell Exchange将MailboxFolderStatistics FolderSize设置为MB,powershell,exchange-server,powershell-remoting,Powershell,Exchange Server,Powershell Remoting,早上好,各位,成为英国人是多么悲伤的一天 无论如何,我正在尝试将MailboxFolderStatistics的FolderSize转换为MB 以下一行: Get-MailboxFolderStatistics Joe.Bloggs | Where-Object { $_.FolderPath -ne "/Deletions" } | Select-Object FolderPath, @{ N = "FolderSize (MB)"; E = { $_.FolderSize.T

早上好,各位,成为英国人是多么悲伤的一天

无论如何,我正在尝试将
MailboxFolderStatistics
FolderSize
转换为MB

以下一行:

Get-MailboxFolderStatistics Joe.Bloggs |
    Where-Object { $_.FolderPath -ne "/Deletions" } |
    Select-Object FolderPath, @{ N = "FolderSize (MB)"; E = { $_.FolderSize.ToMB() } }
使用Exchange命令行管理程序时工作正常

但是,如果我在我的一个交换盒中使用远程PS会话,我不会从
FolderSize
中得到任何东西


有什么想法吗?

这是因为您在服务器上运行的Exchange命令行管理程序包含一个名为Microsoft.Exchange.Data.ByteQuantifiedSize的类型,该类型通过远程处理转换为
System.String
。前者公开了
tomber()
方法,后者则不公开

我已经写了一个变通方法,但可能有一个更简单和/或更漂亮的方法:

Get-MailboxFolderStatistics Joe.Bloggs |
    Where-Object { $_.FolderPath -ne "/Deletions" } |
    Select-Object FolderPath, @{
        N = "FolderSize (MB)";
        E = {
            "{0:N2}" -f ((($_.FolderSize -replace "[0-9\.]+ [A-Z]* \(([0-9,]+) bytes\)","`$1") -replace ",","") / 1MB)
        }
    }

它使用正则表达式将难看的字符串(例如:
3.712kb(3801字节)
)转换为可用的数字。在我的系统
上,
不是有效的数字分组符号,因此我也必须将其从字符串中删除。

您可以使用以下几行获取以[小数]表示的$FolderSize

Select-Object  @{
N = "FS_MB";
        E = {
            [math]::round( ([decimal](($_.FolderSize -replace "[0-9\.]+ [A-Z]* \(([0-9,]+) bytes\)","`$1") -replace ",","") / 1MB),2)
        }
}

通常,在查看文件夹大小时,需要按大小降序对其进行排序。为了实现这一点,我们需要知道FolderAndSubfolderSize(以字节为单位),并将其存储在
bigint
属性中,而不是
System.String
。把字节转换成Kb,Mb,Gb不是火箭科学,所以我这里不讨论这个问题

用于动态添加新属性FolderAndSubfolderSizeBytes的行内语法(我使用了倒勾来拆分多行,仅为了清晰起见)

Long hand将新属性添加到变量对象,以便以后重复使用

$mb = Get-EXOMailbox -Identity user.name@domain.com | Get-EXOMailboxFolderStatistics
foreach ($folder in $mb) {
    $folder | Add-Member -NotePropertyName FolderSizeBytes -NotePropertyValue ((($folder.FolderSize -replace '^(.*\()(.*)(\sbytes\))$','$2').Replace(',','')) -as [bigint])
    $folder | Add-Member -NotePropertyName FolderAndSubfolderSizeBytes -NotePropertyValue ((($folder.FolderAndSubfolderSize -replace '^(.*\()(.*)(\sbytes\))$','$2').Replace(',','')) -as [bigint])
}
$mb | Select Name,FolderPath,FolderAndSubfolderSize,FolderAndSubfolderSizeBytes | Sort-Object -Property FolderAndSubfolderSizeBytes -Descending | ft

如果您将其分解为单个命令,那么第一个(
Get-MailboxFolderStatistics Joe.Bloggs
)是否会给出结果?嗨,Sodawillow,是的。如果我得到mailboxFolderStatistics Joe.Bloggs |选择FolderPath,Foldersize我得到的文件夹路径和Foldersize格式是“2.364 MB(2478818字节)”,先生,你是个英雄。非常感谢。工作是一种享受
$mb = Get-EXOMailbox -Identity user.name@domain.com | Get-EXOMailboxFolderStatistics
foreach ($folder in $mb) {
    $folder | Add-Member -NotePropertyName FolderSizeBytes -NotePropertyValue ((($folder.FolderSize -replace '^(.*\()(.*)(\sbytes\))$','$2').Replace(',','')) -as [bigint])
    $folder | Add-Member -NotePropertyName FolderAndSubfolderSizeBytes -NotePropertyValue ((($folder.FolderAndSubfolderSize -replace '^(.*\()(.*)(\sbytes\))$','$2').Replace(',','')) -as [bigint])
}
$mb | Select Name,FolderPath,FolderAndSubfolderSize,FolderAndSubfolderSizeBytes | Sort-Object -Property FolderAndSubfolderSizeBytes -Descending | ft