Rounding off numbers to 2 decimal places.

D

Don Pedro

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"
 

My Computer

C

Chris Dent

A couple of ways for you here. If you plan to sort on field at all you
should ensure it remains numeric, and that would make the Round method
more appropriate.


$Value = 2.3456
# Numeric output
$NewValue = [Math]::Round($Value, 2)
$NewValue
$NewValue.GetType()
# String output
$NewValue = '{0:N2}' -f $Value
$NewValue
$NewValue.GetType()


HTH

Chris

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"
>
--
Blog: http://www.indented.co.uk
DnsShell: http://code.msdn.microsoft.com/dnsshell
 

My Computer

L

Larry__Weiss

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"
 

My Computer

D

Don Pedro

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"
> .
>
 

My Computer

C

Chris Dent

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"
>>>
>> .
>>
>>
--
Blog: http://www.indented.co.uk
DnsShell: http://code.msdn.microsoft.com/dnsshell
 

My Computer

L

Larry__Weiss

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"
>>> .
>>>
>
 

My Computer

C

Chris Dent

You'd be pushed to find a better resource than MSDN itself, this
particular static method is fully documented here:

http://msdn.microsoft.com/en-us/library/system.math_members.aspx

The values for the MidPointRounding enumeration are here:

http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx

In PS you can get the members of the Enumeration with:

[Enum]::GetNames([MidPointRounding])

Or both names and values with this (or some variation of this):

[Enum]::GetNames([MidPointRounding]) | Select-Object @{n='Name';e={ $_
}}, @{n='Value';e={ [Int][MidPointRounding]$_ }}

You'd still be short of the meaning, so MSDN isn't really cut out of the
loop with that.

Chris

Larry__Weiss wrote:

> 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"
>>>> .
>>>>
>>
--
Blog: http://www.indented.co.uk
DnsShell: http://code.msdn.microsoft.com/dnsshell
 

My Computer

D

Don Pedro

Thanks to you both.... Excellent solutions.

"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"
> >>>
> >> .
> >>
> >>
>
> --
> Blog: http://www.indented.co.uk
> DnsShell: http://code.msdn.microsoft.com/dnsshell
> .
>
 

My Computer

L

Larry__Weiss

.NET and PowerShell

Thanks!

Now Microsoft needs to add a PowerShell column to the examples
in the Syntax and Examples section of those webpages like

http://msdn.microsoft.com/en-us/library/system.math_members.aspx

I suppose there should be a fairly mechanical way to translate the
C# examples to PowerShell. Has anyone written up a description
of how to translate C# to PowerShell?

I did see this video by Doug Finke of an edit session of translation
of C# to PowerShell and some iterative refactoring thereafter.

http://dougfinke.com/video/CSharpToPowerShell..html

- Larry


On 5/14/2010 4:05 AM, Chris Dent wrote:

>
> You'd be pushed to find a better resource than MSDN itself, this
> particular static method is fully documented here:
>
> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>
> The values for the MidPointRounding enumeration are here:
>
> http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx
>
> In PS you can get the members of the Enumeration with:
>
> [Enum]::GetNames([MidPointRounding])
>
> Or both names and values with this (or some variation of this):
>
> [Enum]::GetNames([MidPointRounding]) | Select-Object @{n='Name';e={ $_
> }}, @{n='Value';e={ [Int][MidPointRounding]$_ }}
>
> You'd still be short of the meaning, so MSDN isn't really cut out of the
> loop with that.
>
> Chris
>
> Larry__Weiss wrote:

>> 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
>>
 

My Computer

C

Chris Dent

Re: .NET and PowerShell

A fair number do have PS examples, especially in the DirectoryServices
branches. I was trying to write some for the old iADS interfaces, but it
never seems to successfully submit.

I should add a few examples to the System.Net.Sockets members since I
enjoy using those so much.

Chris

Larry__Weiss wrote:

> Thanks!
>
> Now Microsoft needs to add a PowerShell column to the examples
> in the Syntax and Examples section of those webpages like
>
> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>
> I suppose there should be a fairly mechanical way to translate the
> C# examples to PowerShell. Has anyone written up a description
> of how to translate C# to PowerShell?
>
> I did see this video by Doug Finke of an edit session of translation
> of C# to PowerShell and some iterative refactoring thereafter.
>
> http://dougfinke.com/video/CSharpToPowerShell..html
>
> - Larry
>
>
> On 5/14/2010 4:05 AM, Chris Dent wrote:

>>
>> You'd be pushed to find a better resource than MSDN itself, this
>> particular static method is fully documented here:
>>
>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>
>> The values for the MidPointRounding enumeration are here:
>>
>> http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx
>>
>> In PS you can get the members of the Enumeration with:
>>
>> [Enum]::GetNames([MidPointRounding])
>>
>> Or both names and values with this (or some variation of this):
>>
>> [Enum]::GetNames([MidPointRounding]) | Select-Object @{n='Name';e={ $_
>> }}, @{n='Value';e={ [Int][MidPointRounding]$_ }}
>>
>> You'd still be short of the meaning, so MSDN isn't really cut out of the
>> loop with that.
>>
>> Chris
>>
>> Larry__Weiss wrote:

>>> 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
>>>
--
Blog: http://www.indented.co.uk
DnsShell: http://code.msdn.microsoft.com/dnsshell
 

My Computer

L

Larry__Weiss

Re: .NET and PowerShell

I occasionally see a "Community" comment that adds PowerShell
examples, but I have not seen any articles that actually show
a PowerShell tab alongside the other languages.

- Larry


On 5/14/2010 10:19 AM, Chris Dent wrote:

>
> A fair number do have PS examples, especially in the DirectoryServices
> branches. I was trying to write some for the old iADS interfaces, but it
> never seems to successfully submit.
>
> I should add a few examples to the System.Net.Sockets members since I
> enjoy using those so much.
>
> Chris
>
> Larry__Weiss wrote:

>> Thanks!
>>
>> Now Microsoft needs to add a PowerShell column to the examples
>> in the Syntax and Examples section of those webpages like
>>
>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>
>> I suppose there should be a fairly mechanical way to translate the
>> C# examples to PowerShell. Has anyone written up a description
>> of how to translate C# to PowerShell?
>>
>> I did see this video by Doug Finke of an edit session of translation
>> of C# to PowerShell and some iterative refactoring thereafter.
>>
>> http://dougfinke.com/video/CSharpToPowerShell..html
>>
>> - Larry
>>
>>
>> On 5/14/2010 4:05 AM, Chris Dent wrote:

>>>
>>> You'd be pushed to find a better resource than MSDN itself, this
>>> particular static method is fully documented here:
>>>
>>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>>
>>> The values for the MidPointRounding enumeration are here:
>>>
>>> http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx
>>>
>>> In PS you can get the members of the Enumeration with:
>>>
>>> [Enum]::GetNames([MidPointRounding])
>>>
>>> Or both names and values with this (or some variation of this):
>>>
>>> [Enum]::GetNames([MidPointRounding]) | Select-Object @{n='Name';e={ $_
>>> }}, @{n='Value';e={ [Int][MidPointRounding]$_ }}
>>>
>>> You'd still be short of the meaning, so MSDN isn't really cut out of the
>>> loop with that.
>>>
>>> Chris
>>>
>>> Larry__Weiss wrote:
>>>> 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
>>>>
>
 

My Computer

C

Chris Dent

Re: .NET and PowerShell

Sorry yes, that's all I was referring to. It would certainly be nice to
see that.

Larry__Weiss wrote:

> I occasionally see a "Community" comment that adds PowerShell
> examples, but I have not seen any articles that actually show
> a PowerShell tab alongside the other languages.
>
> - Larry
>
>
> On 5/14/2010 10:19 AM, Chris Dent wrote:

>>
>> A fair number do have PS examples, especially in the DirectoryServices
>> branches. I was trying to write some for the old iADS interfaces, but it
>> never seems to successfully submit.
>>
>> I should add a few examples to the System.Net.Sockets members since I
>> enjoy using those so much.
>>
>> Chris
>>
>> Larry__Weiss wrote:

>>> Thanks!
>>>
>>> Now Microsoft needs to add a PowerShell column to the examples
>>> in the Syntax and Examples section of those webpages like
>>>
>>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>>
>>> I suppose there should be a fairly mechanical way to translate the
>>> C# examples to PowerShell. Has anyone written up a description
>>> of how to translate C# to PowerShell?
>>>
>>> I did see this video by Doug Finke of an edit session of translation
>>> of C# to PowerShell and some iterative refactoring thereafter.
>>>
>>> http://dougfinke.com/video/CSharpToPowerShell..html
>>>
>>> - Larry
>>>
>>>
>>> On 5/14/2010 4:05 AM, Chris Dent wrote:
>>>>
>>>> You'd be pushed to find a better resource than MSDN itself, this
>>>> particular static method is fully documented here:
>>>>
>>>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>>>
>>>> The values for the MidPointRounding enumeration are here:
>>>>
>>>> http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx
>>>>
>>>> In PS you can get the members of the Enumeration with:
>>>>
>>>> [Enum]::GetNames([MidPointRounding])
>>>>
>>>> Or both names and values with this (or some variation of this):
>>>>
>>>> [Enum]::GetNames([MidPointRounding]) | Select-Object @{n='Name';e={ $_
>>>> }}, @{n='Value';e={ [Int][MidPointRounding]$_ }}
>>>>
>>>> You'd still be short of the meaning, so MSDN isn't really cut out of
>>>> the
>>>> loop with that.
>>>>
>>>> Chris
>>>>
>>>> Larry__Weiss wrote:
>>>>> 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
>>>>>
>>
 

My Computer

L

Larry__Weiss

Re: .NET and PowerShell

If that happens it will give me great confidence that Microsoft
considers PowerShell to be a "real" .NET language.

- Larry

On 5/14/2010 1:46 PM, Chris Dent wrote:

> Sorry yes, that's all I was referring to. It would certainly be nice to
> see that.
>
> Larry__Weiss wrote:

>> I occasionally see a "Community" comment that adds PowerShell
>> examples, but I have not seen any articles that actually show
>> a PowerShell tab alongside the other languages.
>>
>> On 5/14/2010 10:19 AM, Chris Dent wrote:

>>> A fair number do have PS examples, especially in the DirectoryServices
>>> branches. I was trying to write some for the old iADS interfaces, but it
>>> never seems to successfully submit.
>>> I should add a few examples to the System.Net.Sockets members since I
>>> enjoy using those so much.
>>>
>>> Larry__Weiss wrote:
>>>> Now Microsoft needs to add a PowerShell column to the examples
>>>> in the Syntax and Examples section of those webpages like
>>>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>>>
>>>> On 5/14/2010 4:05 AM, Chris Dent wrote:
>>>>> You'd be pushed to find a better resource than MSDN itself, this
>>>>> particular static method is fully documented here:
>>>>> http://msdn.microsoft.com/en-us/library/system.math_members.aspx
>>>>> The values for the MidPointRounding enumeration are here:
>>>>> http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx
>>>>>
>>>>> Larry__Weiss wrote:
>>>>>> Is there a commonly used reference book that details these .NET
>>>>>> methods?
>>>>>>
 

My Computer

Top