Is there a commonly used reference book that details these .NET
methods?
Even with a method as seemingly simple as [Math]::Round
I get all these possibilities listed by using
Steven Murawski's function get-staticmethoddefinition
available at
http://poshcode.org/968
PS C:> [math] | get-staticmethoddefinition round
static double Round(double a),
static double Round(double value, int digits),
static double Round(double value, System.MidpointRounding mode),
static double Round(double value, int digits, System.MidpointRounding mode),
static decimal Round(decimal d),
static decimal Round(decimal d, int decimals),
static decimal Round(decimal d, System.MidpointRounding mode),
static decimal Round(decimal d, int decimals, System.MidpointRounding mode)
PS C:>
After using Google on "System.MidpointRounding" to find
http://msdn.microsoft.com/en-us/library/system.midpointrounding(VS.85).aspx
and the especially useful "Community" comment there by Thomas Lee
I now can code the variations in PowerShell like
PS C:> [Math]::Round(3.45, 1, [System.MidPointRounding]::ToEven)
3.4
PS C:> [Math]::Round(3.45, 1, [System.MidPointRounding]::AwayFromZero)
3.5
PS C:>
But I'd sure like to find a reference text that shows me all the
possibilities. Or, does the complexity of these frameworks take
them beyond the possibility of being documented with traditionally
bound printed volumes?
- Larry
On 5/13/2010 11:13 AM, Chris Dent wrote:
>
> I would change it a bit, and I would use [Math]::Round in this scenario.
> I hope you find this useful 
>
>
> Function RetrieveData($Server)
> {
> $ShortName = ($Server -Replace '\..*').ToUpper()
> Write-Host $ShortName
> Write-Host $("-" * $ShortName.Length)
>
> Get-MailboxDatabase -Server $Server | Sort-Object Identity | %{
> $UserCount = ($_ | Get-Mailbox | Measure-Object).Count
>
> $Path = [String]::Format('\\{0}\{1}$\{2}',
> $Server,
> $_.EdbFilePath.DriveName.Remove(1).ToString(),
> $_.EdbFilePath.PathName.Remove(0,2))
> $DBSize = [Math]::Round($((Get-Item $Path).Length / 1Gb), 2)
>
> $TotalUsers += $UserCount
> $TotalDBSize += $DBSize
>
> $_ | Select-Object `
> @{n='Database';e={ $_.Name }}, `
> @{n='Size (GB)';e={ $DBSize }}, `
> @{n='Qty Mbxs';e={ ($_ | Get-Mailbox | Measure-Object).Count }}
> }
> Write-Host ""
> Write-Host "Total DB Size is $TotalDBSize GB"
> Write-Host "Total users is $TotalUsers"
> }
> # Call the function
> RetrieveData "SERVER01.CONTOSO.ORG"
>
>
> Don Pedro wrote:
>> Larry, your solution worked first time so I went with that one.
>>
>> Now, if I could get the output to appear with headers per server that
>> would be the icing on the cake...
>>
>> Desired output would be:
>>
>> SERVER01
>> ------------
>> Database Size (GB) Qty Mbxs
>> MBX01 10.00 10
>> MBX02 20.00 20
>> MBX03 30.00 30
>>
>> -----------------------------------------
>> Total Database Size: 60.00 GB
>> Total number of users: 60
>>
>> SERVER02
>> ------------
>> Database Size (GB) Qty Mbxs
>> MBX01 10.00 10
>> MBX02 20.00 20
>> MBX03 30.00 30
>>
>> -----------------------------------------
>> Total Database Size: 60.00 GB
>> Total number of users: 60
>>
>> If you could help that would be awesome.
>>
>>
>> "Larry__Weiss" wrote:
>>
>>> Try
>>>
>>> Write-Host "Total DB Size is $('{0:N2}' -f $TotalDBSize)"
>>> Write-Host "Total users is $('{0:N2}' -f $TotalUsers)"
>>>
>>> - Larry
>>>
>>>
>>> On 5/13/2010 8:05 AM, Don Pedro wrote:
>>>> I have the following script to retrieve mailbox database sizes and
>>>> number of
>>>> users.
>>>>
>>>> However the numbers returned on the mailbox database size is to
>>>> around 12
>>>> decimal places.
>>>>
>>>> I would like
>>>>
>>>> 1. $DBSize be displayed to 2 decimal places.
>>>> 2. $TotalDBSize to be displayed to 2 decimal places.
>>>>
>>>> Any ideas how to modify below script?
>>>>
>>>>
>>>> FUNCTION RetrieveData
>>>> {
>>>> param ($X, $Y)
>>>>
>>>> $db = Get-MailboxDatabase -server $X | sort-object identity
>>>> foreach ($objItem in $db)
>>>> {
>>>> $userCount = 0
>>>> $userDatabase = $objitem | Get-Mailbox
>>>> Foreach ($user in $userDatabase) { $userCount++ }
>>>> $TotalUsers = $TotalUsers + $userCount
>>>> $edbfilepath = $objItem.edbfilepath
>>>> $path = "`\`\" + $Y + "`\" +
>>>> $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+
>>>> $objItem.EdbFilePath.PathName.Remove(0,2)
>>>> $dbpath = Get-ChildItem $path
>>>> $DBSize = ($dbpath.Length/1048576KB)
>>>> $TotalDBSize = $TotalDBSize+$DBSize;
>>>>
>>>> Write-Host $X, $objitem.name, $DBSize, $usercount
>>>> }
>>>> Write-Host "Total DB Size is $TotalDBSize"
>>>> Write-Host "Total users is $TotalUsers"
>>>> }
>>>> # Call Function
>>>> RetrieveData "SERVER01" "SERVER01.CONTOSO.ORG"
>>> .
>>>
>