1

I've got a PowerShell script where I'm collecting a bunch of data and then outputting to an HTML report.
One of the sections is the following:

$VPGSummaryInfo = Get-ZertoVPG | Select VPGName, Priority, Status, ProgressPercentage, ActualRPO | Sort-Object -Property VPGName
    
    $htmlbody += $VPGSummaryInfo | ConvertTo-Html -Fragment

Simple enough.

What I'm trying to do and can't figure out, is how to change the Priority to replace the results. For example, when Priority is 1, change that to 'High'.

I tried to do something like this, but it is giving me an error (not in a place to validate, but I believe it was a Null expression error):

       
       $VPGInfo = @()
       
       $VPGStatus = @{
       1 = "High"; 2 = "Medium"; 3 = "Low"
}
       
       $VPG = Get-ZertoVPG | Select VPGName, Priority, Status, ProgressPercentage, ActualRPO
       
       
       $VPGStat = $VPGStatus[[int]$VPG.Priority]
       
       $VPGObj = New-Object PSObject
       
       $VPGObj | Add-Member NoteProperty -Name "VPG Name" -Value $VPG.VPGName
       $VPGObj | Add-Member NoteProperty -Name "Priority" -Value $VPGStat
       $VPGObj | Add-Member NoteProperty -Name "Status" -Value $VPG.Status
       $VPGObj | Add-Member NoteProperty -Name "Replication Progress Percentage (%)" -Value $VPG.ProgressPercentage
       $VPGObj | Add-Member NoteProperty -Name "Actual RPO (Sec)" -Value $VPG.ActualRPO

       
       $VPGInfo += $VPGObj


       $htmlbody += $VPGInfo | ConvertTo-Html -Fragment       

I am completely open to any method to accomplish this. I have a lot of different scenarios where I'm going to need to do similar replacements. For example, even in the code above, I will be trying to replace the Status to something more readable.

Thanks for any suggestions.

2 Answers2

1

Use a calculated property:

Get-ZertoVPG | Select VPGName, 
  @{Name='Priority'; Expression={ @{ 1="High"; 2="Medium"; 3="Low" }[$_.Priority]}},
  Status, ProgressPercentage, ActualRPO

Note: This assumes that the original .Priority values are [int]-typed (System.Int32; verify with Get-ZertoVPG | Get-Member Priority).

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Sorry, I was going to edit my main reply with examples. My results aren't what I expected, but that's not because of the solution it turns out, it's because of the PS module I think. So your code is right, but I've just got to tweak it to get the results I need (for example, 1 is supposed to be 'High', but for some reason the PS module isn't showing that) – ComputerRecon Aug 05 '20 at 15:04
1

Just in case anyone from the Zerto world stumbles across this, here is what I ultimately did to capture the proper information into a more readable format (using @mklement0 solution)

$VPGSummaryInfo = Get-ZertoVPG | select VPGName,
  @{ Name = 'Priority'; Expression = { @{ 0 = "Low"; 1 = "Medium"; 2 = "High" }[$_.Priority] } },
  @{ Name = 'Status'; Expression = { @{ 0 = "Initializing"; 1 = "Meeting SLA"; 2 = "Not Meeting SLA"; 3 = "RPO Not Meeting SLA"; 4 = "History Not Meeting SLA"; 5 = "Failing Over"; 6 = "Moving"; 7 = "Deleting"; 8 = "Recovered" }[$_.Status] } },
  @{ Name = 'SubStatus'; Expression = { @{
        0 = "None"; 1 = "Initial Sync"; 2 = "Creating"; 3 = "Volume Initial Sync"; 4 = "Sync"; 5 = "Recovery Possible"; 6 = "Delta Sync"; 7 = "Needs Configuration"; 8 = "Error"; 9 = "Empty Protection Group";
        10 = "Disconnected From Peer. No Recovery Points"; 11 = "Full Sync"; 12 = "Volume Delta Sync"; 13 = "Volume Full Sync"; 14 = "Failing Over Committing"; 15 = "Failing Over Before Commit"; 16 = "Failing Over Rolling Back"; 17 = "Promoting"; 18 = "Moving Committing"; 19 = "Moving Before Commit";
        20 = "Moving Rolling Back"; 21 = "Deleting"; 22 = "Pending Remove"; 23 = "Bitmap Sync"; 24 = "Disconnected From Peer"; 25 = "Replication Paused - User Initiated"; 26 = "Replication Paused - System Initiated"; 27 = "Recovery Storage Profile Error"; 28 = "Unknown"; 29 = "Rolling Back";
        30 = "Recovery Storage Error"; 31 = "Journal Storage Error"; 32 = "VM Not Protected Error"; 33 = "Journal or Recovery Missing Error"; 34 = "Added VMs in Initial Sync"; 35 = "Replication Paused for Missing Volume"; 36 = "Stopping Fot Failure"; 37 = "Rolling Back FailOver Live Failure"; 38 = "Rolling Back Move Failure"; 39 = "Splitting Committing"; 40 = "Prepare Preseed" 
      }[$_.SubStatus] } 
  },
  @{ Name = 'Progress Percentage (%)'; Expression = { $_.ProgressPercentage } },
  @{ Name = 'Actual RPO (Sec)'; Expression = { $_.ActualRPO } } | Sort-Object -Property VPGName
              
$htmlbody += $VPGSummaryInfo | ConvertTo-Html -Fragment
mklement0
  • 382,024
  • 64
  • 607
  • 775