Output Display

Welcome Forums General PowerShell Q&A Output Display

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 6 months ago.

  • Author
  • #57122

    Topics: 12
    Replies: 17
    Points: 2
    Rank: Member

    I have the below code:

    $clusters="pcclus4", "pctclus7"

    Foreach($cluster in $clusters)
    $VMS += Get-VM –ComputerName (Get-ClusterNode –Cluster $cluster) |Where-Object { $_.Name -like '*FS*' }
    $NoReplica=$VMS |where-object {$_.ReplicationState -eq "disabled"} |ft Name | Out-String
    $text= "Servers without replica enabled in cluster $clusters are" + "`r`n" + $NoReplica
    Send-MailMessage -To "lala@lala.com" -From "cluster@lala.com" -Subject "FS without Hyper-V Replica Enabled" -SmtpServer "lalamail.lala.com" -Body $text

    I am getting a report on email looking like

    HostName Name
    ——– —- tFS11 PC3FS21 PCADFS21 tFS16 PC7FS22

    This output contains the FS from both clusters. I would like to get a report formatted on a table or at least to have the name of the cluster and then the FS then the other cluster and its FS below. For e.g.
    FS on pcclus4
    tFS11 PC3FS21

    FS on pctclus7
    PCADFS21 tFS16 PC7FS22

  • #57128

    Topics: 8
    Replies: 1190
    Points: 639
    Helping Hand
    Rank: Major Contributor

    You should look at the eBooks link above and read the free eBook Creating HTML Reports in PowerShell. You have a LOT more flexibility doing HTML reports rather than trying to build emails as a string. Try this:

    $clusters="pcclus4", "pctclus7"
    $vms = foreach($cluster in $clusters){
        Get-VM –ComputerName (Get-ClusterNode –Cluster $cluster) | 
        Where-Object { ($_.Name -like '*FS*') -and ($_.ReplicationState -eq "disabled")}
    $body = $vms | ConvertTo-HTML -Title "Servers without replica enabled in cluster" | Out-String
    $mailParams = @{
        To = "lala@lala.com" 
        From = "cluster@lala.com" 
        Subject = "FS without HyperV Replica Enabled" 
        SmtpServer = "lalamail.lala.com" 
        Body = $body
    Send-MailMessage @mailParams
  • #57131

    Topics: 12
    Replies: 17
    Points: 2
    Rank: Member

    Not working like this only get an infinit message

    Servers without replica enabled in cluster

The topic ‘Output Display’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort