Question : Convert Output from Powershell to HTML

I have the following script running against my Exchange 2003 environment that displays, in PowerGui, the status of my Exchange mail stores.  It scans each mail store and displays if it's mounted or dismounted.  I get the values in PowerGui, but when I convert the output to HTML I only receive the data listed within the Length column.

function func_Get-MailStore_Status()
{
$snServername= ‘server1', 'server2'
ForEach ($Srv in $snServerName)
{
  # Show some progress indicators
  Write-Host "Starting Loop for $snServerName"

  Write-Host "Executing WMI Query"

  $wmiServer = Get-Wmiobject Exchange_Server -Computer $snServerName `
    -Namespace root\MicrosoftExchangeV2 #-ErrorAction SilentlyContinue

  Write-Host "Creating CDOEXM Objects"

  $cdoexmIExchangeServer = New-Object -com CDOEXM.ExchangeServer
  $cdoexmIStorageGroup = New-Object -com CDOEXM.StorageGroup
  $cdoexmIMailboxStoreDB = New-Object -com CDOEXM.MailboxStoreDB

  Write-Host "Opening Exchange Server Data Source"

    $cdoexmIExchangeServer.Datasource.Open($Srv)

  Write-Host "Checking StorageGroups"

  foreach ($sgStoragegroup in $cdoexmIExchangeServer.StorageGroups)
  {
    if ($sgStoragegroup.Indexof("CN=Recovery Storage Group") -eq 0)
    {
      "Recovery Storage Group"
    }
    else
    {
      Write-Host "Opening Storage Group $sgStoragegroup"

      $cdoexmIStorageGroup.DataSource.Open(('LDAP://' + $sgStoragegroup))

      foreach ($MailStore in $cdoexmIStorageGroup.MailboxStoreDBs)
      {

        Write-Host "OPening Store $MailStore"

        $cdoexmIMailboxStoreDB.DataSource.Open(('LDAP://' + $MailStore))
        if ($cdoexmIMailboxStoreDB.Status -eq 0)
        {
          "$($cdoexmIMailboxStoreDB.Name) Mounted"
        }
        if ($cdoexmIMailboxStoreDB.Status -eq 1)
        {
          "$($cdoexmIMailboxStoreDB.Name) DisMounted"
        }
                  }
    }
  }
}

}
func_Get-MailStore_Status | Select-Object

Answer : Convert Output from Powershell to HTML


I would have thought this would work, but I can't test it...

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Function Get-DatabaseStatus
{
  Param(
    [String[]]$Server
  )

  $Server | ForEach-Object {

    # Show some progress indicators
    Write-Host "Starting Loop for $_"
    Write-Host "Executing WMI Query"

    $wmiServer = Get-Wmiobject Exchange_Server -Computer $_ `
      -Namespace root\MicrosoftExchangeV2 #-ErrorAction SilentlyContinue

    Write-Host "Creating CDOEXM Objects"

    $cdoexmIExchangeServer = New-Object -com CDOEXM.ExchangeServer
    $cdoexmIStorageGroup = New-Object -com CDOEXM.StorageGroup
    $cdoexmIMailboxStoreDB = New-Object -com CDOEXM.MailboxStoreDB

    Write-Host "Opening Exchange Server Data Source"

    $cdoexmIExchangeServer.Datasource.Open($_)

    Write-Host "Checking StorageGroups"

    $cdoexmIExchangeServer.StorageGroups | 
      Where-Object { $_.IndexOf("CN=Recovery Storage Group") -ne 0 } |
      ForEach-Object {
        Write-Host "Opening Storage Group $_"

        $cdoexmIStorageGroup.DataSource.Open(('LDAP://' + $_))
        $cdoexmIStorageGroup.MailboxStoreDBs | ForEach-Object {
  
          Write-Host "OPening Store $MailStore"

          $cdoexmIMailboxStoreDB.DataSource.Open(('LDAP://' + $_))

          $cdoexmIMailboxStoreDB | Select-Object Name,
            @{n='Status';e={ If ($_.Status -eq 0) { "Mounted" } Else { "Dismounted" } }}
        }
      }
    }
  }
}

Get-DatabaseStatus "server1", "server2" | ConvertTo-Html
Random Solutions  
 
programming4us programming4us