sus42

A Blog on Wndows Server and Microsoft Exchange by Thomas Pätzold

Archive for January 2013

Advanced Mailboxstatistics

leave a comment »


As an administrator of a large Exchange System you have configured a mailboxquota for each mailbox. But the interesting question is what is the ratio between the configured quota and the used mailboxstore. In order to get this value you have to create your own Windows Powershell function.

The following function enumerates all data and stores it in a custom object. So you are able to work with this object.

function get-mailboxquotausage {
<#
.SYNOPSIS
	This function enumerates the configured quota and used mailboxstore for each mailaddress
	of a maildomain. The user is able to specify the maildomain as a parameter to this function.
.DESCRIPTION
	This script enumerates all mailaddresses from one primary maildomain. Displayname, primary SMTP address, prohibit send quota and the used mailboxstore are displayed.
.PARAMETER Maildomain
	This parameter specifies the maildomain this function will work on.
.EXAMPLE
	get-mailboxquotausage -maildomain aixtest.de
	
	Description
	===========
	This command will show the displayname, primary SMTP address, prohibit send quota and used mailboxstore for the domaine @aixtest.de
	
.EXAMPLE
	get-mailboxquotausage -maildomain aixtest.de | select displayname, @{label="size (MB)"; expression={"{0,0:N0}" -f $_.size}}, @{label="quota (MB)"; expression={"{0,0:N0}" -f $_.quota}}
	

	Description
	============
	This command will show the displayname, primary SMTP address, prohibit send quota and used mailboxstore for the domaine @aixtest.de.
	The displayed values will be displayed with a decimal point according to the configured language setting.
#>




[CmdletBinding()]
param([Parameter(Mandatory=$True, ValueFromPipeline=$True)][string]$maildomain)

begin {
}


process{
$delete = 0
$result = @()
$users=get-mailbox |? {$_.primarysmtpaddress -like "*$maildomain*"}

foreach ($user in $users) {

	$userstats=Get-MailboxStatistics $user 

	$obj=new-object psobject
	$obj = @{}
	$obj.add("Displayname", $user.displayname)
	$obj.add("Mailaddress", $user.primarysmtpaddress)
	write-host $user.primarysmtpaddress
	if (-not $user.prohibitsendquota.isunlimited) {
		$obj.add("Quota", ($user.prohibitsendquota.value.toMB()))
	} else {
		$obj.add("Quota", "unlimited")
	}
	$obj.add("Size", ($userstats.totalitemsize.value.toMB()))
	$result += new-object -type PSObject -Property $obj
}
$result
}

end{}

}
Advertisements

Written by Thomas Pätzold

January 28, 2013 at 9:40 pm

UNIX2DOS using Powershell

leave a comment »


Today I was asked to convert a file from the UNIX fileformat to the DOS fileformat.
As you probably know the format is different in the last character of each line. The DOS format ends with a carriage return (Cr) line feed (Lf) character whereas the UNIX format uses the line feed (Lf) character.
So this is a very simple task using Powershell

get-content <filename> |% {$_.replace("`n", "`r`n")} | out-file -filepath <new filename>

Remember the “%” means foreach-object. So this oneliner runs through the whole file and replaces the Lf with the CrLf character.

If you need a solution to use in a pipeline like the UNIX2DOS Unix command write a function that accepts the input from pipeline. The function looks like

function unix2dos{
param([Parameter(Mandatory=$true, ValueFromPipeline=$True)][String]$line)
begin {}
process {
$result = [string]$line.replace("`n","`r`n")
$result
}
end {}
}

Call this function like:

get-content <filename> | unix2dos | out-file -filepath <new filename>

If you put this function in your Powershell profile, you are able to use is anytime anywhere.

Written by Thomas Pätzold

January 21, 2013 at 9:59 pm

%d bloggers like this: