Output Display

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Bill M Bill M 3 weeks, 5 days ago.

  • Author
    Posts
  • #57122
    Profile photo of Bill M
    Bill M
    Participant

    I have the below code:

    $clusters="pcclus4", "pctclus7"

    $VMS=@()
    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
    Profile photo of Bill M
    Bill M
    Participant

    Not working like this only get an infinit message

    Servers without replica enabled in cluster
    VMNameVMIdIdNameStateIntegrationServicesStateOperationalStatusPrimaryOperationalStatusSecondaryOperationalStatusStatusDescriptionsPrimaryStatusDescriptionSecondaryStatusDescriptionStatusHeartbeatReplicationState

You must be logged in to reply to this topic.