JO
 New Member Posts:5

 |
| 05 Feb 2010 07:33 PM |
|
First off just want to say I am not an exchange person and just started messing with PowerShell today. I use ILM 2007 to provision mailboxes to the Exchange 2007. A requirement I have from our systems team is I have to provision a mailbox on the least used DB by space. Right now in our test environment we have two servers with 14 storage groups each. I received this script from the consultant that set up the exchange servers but I do not get any output from this when I run from the shell.
$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true -and $_.name -eq "server00" -or $_.name -eq "server01"}
foreach ($server in $exchangeservers){ foreach ($db in get-mailboxdatabase -server $server) {
$dbPath = $db.EdbFilePath -replace "\\","\\" # for use in the WMI filter $dbSize = (get-wmiobject cim_logicalfile -computer $server -filter "name='$dbPath'" -property filesize).filesize
$retObj = new-object psobject $retObj | add-member noteproperty -name "Server" -value $db.Server $retObj | add-member noteproperty -name "Name" -value $db.Identity $retObj | add-member noteproperty -name "Size(MB)" -value ("{0:n1}" -f ($dbSize/1MB)) $retObj | add-member noteproperty -name "DN" -value $db.DistinguishedName
$retobj
} $Database = ($retobj |sort-object {[int] $_."size(mb)"}) }
Hope this makes sense and hope someone can either help me make sense of this script or provide some input on how to accomplish this task.
Thanks in advance.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 07 Feb 2010 12:43 AM |
|
Try this, you can run it on the Exchange server or on your admin machine (needs excahnge admin tools): function Convert-LocalPathToUNC { param( [string]$ComputerName=$env:COMPUTERNAME, [string]$Path=$(throw "Path cannot be empty.") ) if(Test-Path $Path -IsValid) { $Path -replace "^(.)(.)","\\$computerName\`$1$" } else { Write-Error "Invalid Path. The syntax of the path is incorrect." } } Get-ExchangeServer | where {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -and ($_.name -eq "server00" -or $_.name -eq "server01")} | Foreach-Object{ $server = $_ $_ | Get-MailboxDatabase | Select-Object @{n="Server";e={$server.Name}},Name,EdbFilePath,@{n="Size(MB)";e={ (dir (Convert-LocalPathToUNC -ComputerName $server.Name -Path $_.EdbFilePath)).Length/1MB }},DistinguishedName } | Sort-Object "Size(MB)"
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
JO
 New Member Posts:5

 |
| 07 Feb 2010 01:46 PM |
|
Thanks Shay, Here is a screen shot of what I did. Am I doing something wrong? I was expecting to see some sort of output at the end. Thanks for your help.  |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
JO
 New Member Posts:5

 |
| 08 Feb 2010 08:59 AM |
|
Shay, I put it in a script on C: drive named test.ps1 and I opened the exchange shell tool. and I ran this on my command line c:\test.ps1 and nothing happened just went to the c: prompt again.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
JO
 New Member Posts:5

 |
| 10 Feb 2010 07:42 AM |
|
Yes it is.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 11 Feb 2010 06:07 AM |
|
Just to make sure cluster is the problem, can you hard code the active node name ( Convert-LocalPathToUNC -ComputerName ActiveNodeName -Path $_.EdbFilePath) and try again? |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
JO
 New Member Posts:5

 |
| 17 Mar 2010 03:50 PM |
|
Shay, sorry kind of got pulled off this project for a while but I am back...I was wondering if something like this would work: $exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true -and $_.name -eq "server1" -or $_.name -eq "server2"} foreach ($server in $exchangeservers) { (Get-MailboxDatabase | foreach { get-childitem $_.edbFilePath | select-object name,length} | sort -property length )[0] } I ran that but I get a "Cannot index into a null array." Not to sure what is the null value...well and besides that...will this shortened script get me to where I need to be? |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|