Creating table

Hi

I have the following script below which reports on disk space for Exchange DAGS and send it in an email, at the moment its a bit messy and creates 3 lists.  What I would like to do is put all the information into 1 table rather then 3 lists, is this possible?

$servernames = @('GRPMBX1001','GRPMBX1002')
$smtpsettings = @{
To = David@Email.com
From = ExchangeStats@Email.com
Subject = Exchange Server Space Report for $((Get-Date).ToShortDateString())
SmtpServer = SMTPRELAY.Email.com
}

$Message1 = Get-WmiObject -computer $servernames win32_volume|where-object {$_.caption -ne $null -and $_.label -ne System Reserved -and $_.drivetype -eq 3}|select-object __SERVER,Name,
@{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}},
@{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}},
@{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}} | sort name | convertto-html 

$Message2 = get-MailboxDatabase -Status dag01* | select name,@{Name="InUse";Expression={$_.DatabaseSize- $_.AvailableNewMailboxSpace}} | select name,@{L='DAG Size';E={$_.InUse.toGB()}} | sort name | convertto-html 

$message3 = Get-MailboxDatabaseCopyStatus * | select name, status | sort name | ConvertTo-Html

Send-MailMessage @smtpsettings -Body "$Message1 $Message2 $Message3" -BodyAsHTML

July 6th, 2015 3:35am

Hi SaintsDTM,

Remove all the '| ConvertTo-Html' from the $messages

And add this

$Final = "$Message1 $Message2 $Message3" | ConvertTo-Html

Send-MailMessage @smtpsettings -Body $Final -BodyAsHTML

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 4:17am

Thanks for the reply, I'm getting this error when i do that now:

Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. 

Specified method is not supported.
At C:\Exchange - Size Script.ps1:21 char:38
+ Send-MailMessage @smtpsettings -Body $final -BodyAsHTML
+                                      ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage

July 6th, 2015 4:35am

Hi,

Try this:

Send-MailMessage @smtpsettings -Body [string]$Final -BodyAsHTML

Send-MailMessage @smtpsettings -Body "$Final" -BodyAsHTML

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 7:37am

Hi SaintsDT,

the basic issue with your scriptblock is that you gather data from different sources, but do not combine it before exporting it for human eyes.

Basically, what you are looking for is a way to combine multiple pieces of information into a single object before passing it on. Here's an example solution:

$servernames = @('GRPMBX1001', 'GRPMBX1002') $smtpsettings = @{ To = "David@Email.com" From = "ExchangeStats@Email.com" Subject = "Exchange Server Space Report for $((Get-Date).ToShortDateString())" SmtpServer = "SMTPRELAY.Email.com" } $Data = @() foreach ($Server in $Servernames) { $EX = Get-ExchangeServer -Identity $Server $DBs = $EX | Get-MailboxDatabase -Status dag01* foreach ($DB in $DBs) { $VolData = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$($DB.EdbFilePath.DriveName)\\'" $VolLogs = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$($DB.LogFolderPath.DriveName)\\'" $Props = @{ Server = $Server Database = $DB.Name DatabaseSizeInUse = "{0:N2}" -f (($DB.DatabaseSize - $DB.AvailableNewMailboxSpace).ToBytes() / 1GB) DatabaseCopyState = ($DB | Get-MailboxDatabaseCopyStatus).Status DataCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB) DataFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB) DataFreePercent = "$("{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 100))%" LogCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB) LogFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB) LogFreePercent = "$("{0:N2}" -f ($VolData.FreeSpace / $VolData.Capacity * 100))%" } $Data += New-Object PSObject -Property $Props } }

$Body = $Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html Send-MailMessage @smtpsettings -Body $Body -BodyAsHTML


Note where I build a hash table (named $props) and then build a PSObject type of object based upon that.

Cheers,

July 6th, 2015 7:59am

Thanks but i'm getting this error message:

Get-MailboxDatabase : The input object cannot be bound to any parameters for the command either because the 
command does not take pipeline input or the input and its properties do not match any of the parameters that 
take pipeline input.
At line:14 char:15
+     $DBs = $EX | Get-MailboxDatabase -Status dag01*
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (GRPMBX1001:PSObject) [Get-MailboxDatabase], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Exchange.Management.SystemConfigurationTasks.GetMai 
   lboxDatabase

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 12:31pm

New question.  You cannot use a wildcard and -status is not a property.

July 6th, 2015 12:35pm

Try my function which can handle multiple tables and adds pretty grid lines and coloring.

http://www.bryanvine.com/2015/06/powershell-script-convertto-htmltable.html

 
  • Edited by Bryan_Vine 9 hours 53 minutes ago fixed link
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:19pm

Try my function which can handle multiple tables and adds pretty grid lines and coloring.

http://www.bryanvine.com/2015/06/powershell-script-convertto-htmltable.html

 
  • Edited by Bryan_Vine Monday, July 06, 2015 9:16 PM fixed link
July 6th, 2015 9:15pm

Try my function which can handle multiple tables and adds pretty grid lines and coloring.

http://www.bryanvine.com/2015/06/powershell-script-convertto-htmltable.html

 
  • Edited by Bryan_Vine Monday, July 06, 2015 9:16 PM fixed link
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 9:15pm

Hi SaintDTm,

Did you try my updated code? What was the error this time.

July 7th, 2015 3:11am

Thanks but i'm getting this error message:

Get-MailboxDatabase : The input object cannot be bound to any parameters for the command either because the 
command does not take pipeline input or the input and its properties do not match any of the parameters that 
take pipeline input.
At line:14 char:15
+     $DBs = $EX | Get-MailboxDatabase -Status dag01*
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (GRPMBX1001:PSObject) [Get-MailboxDatabase], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Exchange.Management.SystemConfigurationTasks.GetMai 
   lboxDatabase

Hi,

ok ... this cmdlet should accept an Exchange Server by pipeline. Oh well ... try this:

# Old line
$DBs = $EX | Get-MailboxDatabase -Status dag01*

# New Line
$DBs = Get-MailboxDatabase -Status -Server $EX

Cheers,
Fred

PS: What Exchange Version are you scripting against and what is its patch

Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 3:20am

Hi Fred,

Thanks again for the help! I'm still getting powershell error 

 

Method invocation failed because [System.Int32] does not contain a method named 'ToBytes'.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:21 char:3
+         $Props = @{
+         ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I then receive the email but its just from one DAG over and over again with Databasesizeinuse blank.

Thanks again!!

Also its Exchange 2010 SP1



  • Edited by SaintsDT 23 hours 38 minutes ago
July 7th, 2015 3:29am

Hi Satyajit,

Thank you for the help but I'm after the information Fred has supplied.

Thanks again!

Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 3:32am

Hi Fred,

Thanks again for the help! I'm still getting powershell error 

 

Method invocation failed because [System.Int32] does not contain a method named 'ToBytes'.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:21 char:3
+         $Props = @{
+         ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I then receive the email but its just from one DAG over and over again with Databasesizeinuse blank.

Thanks again!!

Also its Exchange 2010 SP1



Hi Saints,

first, let's fix that error:

# Old Line:
DatabaseSizeInUse = "{0:N2}" -f (($DB.DatabaseSize - $DB.AvailableNewMailboxSpace).ToBytes() / 1GB)

# New Line
DatabaseSizeInUse = "{0:N2}" -f (($DB.DatabaseSize - $DB.AvailableNewMailboxSpace) / 1GB)

Make sure to manually verify the result once, just to be sure.

As for the duplicate entries:
Well ... what my scriptblock does is iterate over each of the listed servers and retrieves all Mailbox Databases from them. Then for each of those mailboxes it returns storage statistics. So yeah, it'll produce duplicates in a DAG.

Note however that the local storage statistics are not necessarily duplicate, unless you have identical setups on both servers with exactly the same drives and no other usage. If you truly have a clean setup the data will probably be redundant though.

Options:

- Keep the redundant data (Pro: You get a chance to notice if the DAG fails due to discrepancies in data; Contra: You'll get a lot of data, possibly causing you to ignore it alltogether)
- Filter out the redundant data: You can filter out redundant entries. Easiest place to do so is directly before exporting to html. This might do the trick:

# Old Line
$Body = $Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html

# New Line
$Body = $Data | Group Database | %{$_.Group | Select -First 1} | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html

Cheers,
Fred

July 7th, 2015 3:59am

Hi Fred, thanks again for your help!

I'm not getting the error now when running it but the results aren't right

  1. DatabaseSizeinUse is report 0 for all databases
  2. Every database is reporting the same data i.e. logfree id 67 for everyone, logfreepercent is 49% for everyone etc

Thanks again!!!!!!

Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 4:14am

Hi Saints,

let's deal with the first issue first. Try running this command the same way you are running your mail script:

Get-MailboxDatabase -Status | gm DatabaseSize,AvailableNewMailboxSpace

And post the result.

As for the second:
Depending upon your circumstances, that might well be how it is. If ...
- All your databases are on the same disk for each server in the DAG and ...
- All partitions have the same base size and ...
- All partitions are solely used for your Exchange DAG ...
Then wouldn't you always get the same result?

If that's not how it should be, then it's time to check just what the heck is happening in  the WMI query (Append a "-Debug" Parameter to the WMI Queries).

Cheers,
Fred

July 7th, 2015 4:39am

Hi Fred,

This is the results of that command:

[PS] C:\Windows\system32>Get-MailboxDatabase -Status | gm DatabaseSize,AvailableNewMailboxSpace

TypeName: Microsoft.Exchange.Data.Directory.SystemConfiguration.MailboxDatabase

Name                     MemberType Definition
----                     ---------- ----------
DatabaseSize             Property   System.Nullable[Microsoft.Exchange.Data.ByteQuantifiedSize] DatabaseSize {get;}
AvailableNewMailboxSpace Property   System.Nullable[Microsoft.Exchange.Data.ByteQuantifiedSize] AvailableNewMailboxS...

When i first ran my script (initial post) it would return all the correct information. Each mailbox server have 25 dags and each one is on a separate lun which are the same size but the logfiles, dag size, free space and free% are all different

Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 5:05am

Hi Fred,

Thanks again for the help! I'm still getting powershell error 

 

Method invocation failed because [System.Int32] does not contain a method named 'ToBytes'.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:21 char:3
+         $Props = @{
+         ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I then receive the email but its just from one DAG over and over again with Databasesizeinuse blank.

Thanks again!!

Also its Exchange 2010 SP1



  • Edited by SaintsDT Tuesday, July 07, 2015 7:31 AM
July 7th, 2015 7:27am

Hi Fred,

Thanks again for the help! I'm still getting powershell error 

 

Method invocation failed because [System.Int32] does not contain a method named 'ToBytes'.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:21 char:3
+         $Props = @{
+         ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I then receive the email but its just from one DAG over and over again with Databasesizeinuse blank.

Thanks again!!

Also its Exchange 2010 SP1



  • Edited by SaintsDT Tuesday, July 07, 2015 7:31 AM
Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 7:27am

Hi Saints,

ah, I think I see the issue then. Just so I see this correctly:

You Exchange Server has 25 Volumes without any drive letters. Your Exchange access them using a mountpoint (For Example "C:\ExchangeData\DB1" is actually a junction to Volume "{Some Guid}".

In this case my scriptblock would always report the statistics for volume C: (which would obviously be wrong). Alright, this is just conjecture - looking at one of our customer's setup for comparison - but this might just work:

$servernames = @('GRPMBX1001', 'GRPMBX1002')
$smtpsettings = @{
	To = "David@Email.com"
	From = "ExchangeStats@Email.com"
	Subject = "Exchange Server Space Report for $((Get-Date).ToShortDateString())"
	SmtpServer = "SMTPRELAY.Email.com"
}

$Data = @()
foreach ($Server in $Servernames)
{
	$EX = Get-ExchangeServer -Identity $Server
	
	$DBs = Get-MailboxDatabase -Status -Server $EX
	
	foreach ($DB in $DBs)
	{
		$VolData = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$((Split-Path $DB.EdbFilePath.PathName).Replace("\","\\"))\\'"
		$VolLogs = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$($DB.LogFolderPath.PathName.Replace("\","\\"))\\'"
		
		$Props = @{
			Server = $Server
			Database = $DB.Name
			DatabaseSizeInUse = "{0:N2}" -f (($DB.DatabaseSize.ToBytes() - $DB.AvailableNewMailboxSpace.ToBytes()) / 1GB)
			DatabaseCopyState = ($DB | Get-MailboxDatabaseCopyStatus).Status
			DataCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB)
			DataFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB)
			DataFreePercent = "$("{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 100))%"
			LogCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB)
			LogFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB)
			LogFreePercent = "$("{0:N2}" -f ($VolData.FreeSpace / $VolData.Capacity * 100))%"
		}
		
		$Data += New-Object PSObject -Property $Props
	}
}
$Body = $Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html

Send-MailMessage @smtpsettings -Body $Body -BodyAsHTML

Note the difference in the WMI filter. If this does not do it, then you'll have to look up yourself how to map Volume to Database and logs (Though if you'll post the path-relevant properties of one Database and those of its corresponding volume(s), I can later take a look at it and try a rewrite).

Another difference I implemented was for that DatabaseSizeInUse property - maybe in your version they didn't add a proper addition / substraction operator, so I first convert to bytes and then substract. Anyway, given your output, it obviously has the proper type, which is good.

Cheers,
Fred

July 7th, 2015 8:34am

Hi Fred,

Its nearly there but now getting this error message:

Attempted to divide by zero.
At line:28 char:25
+             DataFreePercent = "$("{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 10 ...
+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
 
Attempted to divide by zero.
At line:31 char:24
+             LogFreePercent = "$("{0:N2}" -f ($VolData.FreeSpace / $VolData.Capacity * 100 ...
+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
 
Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. 
Specified method is not supported.
At line:39 char:38
+ Send-MailMessage @smtpsettings -Body $Body -BodyAsHTML
+                                      ~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage
 

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 4:11am

Hi Saints,

the errors mean that the wmi query failed to find anything (which means we need to tweak the filter so it maps volume to database correctly). Alright, now I'll need some information from you to do this for you:

Choose one specific database and list its path properties:

Get-MailboxDatabase "NameOfMailboxDatabase" | FL EdbFilePath, LogFolderPath

Then use this command to retrieve the information of interest for all volumes:

gwmi win32_volume | ft Caption, Name, DeviceID -AutoSize

With the Information from the first query and the information for the correct volume (Only provide the information for the volume on which the Database is stored) from the second query I should be able to make it work flawlessly.

Send-MailMessage

Wellll ... ok, I failed a bit there. Nothing a minor replacement line can't handle:

# Old Line
$Body = $Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html

# New Line
$Body = ($Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html) -join "`n"

Cheers,
Fred

July 8th, 2015 7:04am

Morning Fred,

Sorry for delay getting back to you, worked half day yesterday

I've changed the send-mailmessage and now getting the error message below but the email is coming though with all the information correct information :-) apart from DatabaseCopyState is System.Object[]

Attempted to divide by zero.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:28 char:25
+             DataFreePercent = "$("{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 10 ...
+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
 
Attempted to divide by zero.
At C:\Users\DThorne_a\Desktop\Scripts\Untitled6.ps1:31 char:24
+             LogFreePercent = "$("{0:N2}" -f ($VolData.FreeSpace / $VolData.Capacity * 100 ...
+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException



Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 3:29am

Hi Saints,

those errors are the reason I asked for the other information :)
Just to be sure: The Volume data is correct for those results, even though there are errors?

Now let's fix that CopyState line:

# Old line
DatabaseCopyState = ($DB | Get-MailboxDatabaseCopyStatus).Status

# New line
DatabaseCopyState = $DB | Get-MailboxDatabaseCopyStatus | Select -First 1 -ExpandProperty Status

Cheers,

July 9th, 2015 3:57am

Hi Fred,

All the volume information is correct even though getting that error message

Attempted to divide by zero.
At C:\Scripts\DAGScript.ps1:28 char:25
+             DataFreePercent = "$("{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 10 ...
+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Also I've changed databasecopystatus to the new line which is reporting back now but the data isn't correct.  One of the dags in a fail state and its reported back healthy

Do you still want me to report back on the other information even though the data is correct?

Thanks again 

David

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 4:45am

Hi Saints,

no, if the data is correct, that's ok then.

About the wrong data, however regarding the CopyState ...

Try running this:

Get-MailboxDatabase "NameOfDatabase" | Get-MailboxDatabaseCopyStatus

against the database that is failing but reported as healthy. What kind of result are you getting? One? Two? More? If more than one, what states are those reporting?

Cheers,
Fred

July 9th, 2015 4:53am

Hi Fred,

After running that command its reporting 

Name                                Status
DAG01JD01\GRPMBX1001 Mounted
DAG01JD01\GRPMBX1002 FailedAndSuspended

The report is showing both as mounted

Cheers

David

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 5:44am

Hi Saints,

ah, I can see now what's the matter (and that I'm sadly lacking in experience with DAGs in general). Here's a complete edition that should give you all the information and not throw any errors:

$servernames = @('GRPMBX1001', 'GRPMBX1002')
$smtpsettings = @{
	To = "David@Email.com"
	From = "ExchangeStats@Email.com"
	Subject = "Exchange Server Space Report for $((Get-Date).ToShortDateString())"
	SmtpServer = "SMTPRELAY.Email.com"
}

$Data = @()
foreach ($Server in $Servernames)
{
	$EX = Get-ExchangeServer -Identity $Server
	
	$DBs = Get-MailboxDatabase -Status -Server $EX
	
	foreach ($DB in $DBs)
	{
		# Retrieve Volumes
		$VolData = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$((Split-Path $DB.EdbFilePath.PathName).Replace("\", "\\"))\\'"
		$VolLogs = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$($DB.LogFolderPath.PathName.Replace("\", "\\"))\\'"
		
		# Process Free percent
		try { $DataFreePercent = "{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 100) }
		catch { $DataFreePercent = "{0:N1}" -f -99.9 }
		try { $LogFreePercent = "{0:N1}" -f ($VolLogs.FreeSpace / $VolLogs.Capacity * 100) }
		catch { $LogFreePercent = "{0:N1}" -f -99.9 }
		
		
		$Props = @{
			Server = $Server
			Database = $DB.Name
			DatabaseSizeInUse = "{0:N2}" -f (($DB.DatabaseSize.ToBytes() - $DB.AvailableNewMailboxSpace.ToBytes()) / 1GB)
			DatabaseCopyState = ($DB | Get-MailboxDatabaseCopyStatus | Select-Object -ExpandProperty Status) -join " / "
			DataCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB)
			DataFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB)
			DataFreePercent = "$($DataFreePercent)%"
			LogCapacity = "{0:N2}" -f ($VolLogs.Capacity / 1GB)
			LogFree = "{0:N2}" -f ($VolLogs.FreeSpace / 1GB)
			LogFreePercent = "$($LogFreePercent)%"
		}
		
		$Data += New-Object PSObject -Property $Props
	}
}
$Body = ($Data | Sort-Object Server, Database | Select-Object Server, Database, DatabaseSizeInUse, DatabaseCopyState, DataCapacity, DataFree, DataFreePercent, LogCapacity, LogFree, LogFreePercent | ConvertTo-Html) -join "`n"

Send-MailMessage @smtpsettings -Body $Body -BodyAsHTML

Cheers,
Fred

July 9th, 2015 8:12am

Brilliant!!!!!!!!!!!!! All working now, thank you so much for all your help!!!!!!!

Thanks again

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 8:57am

My Pleasure :)
July 9th, 2015 9:38am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics