0

我需要使用 Powershell-AWS Sdk for AWS Backup 进行报告。

实际上我有当前的报告:

报告示例截图

我想在左侧为每个带有 VolumeId 的原始匹配添加 Name Instance TAG 列,以便更友好地使用,并且如果 Instance 是否备份,则更容易阅读。

谢谢。


# AWS Credentials
Set-AWSCredential -ProfileName XXXX
Set-DefaultAWSRegion -Region XXXXX

$date = (get-date -Format "MM-dd-yyyy" (Get-Date).AddDays(-1)) #Last day


$Body = @"
<style>
      body {
      background-color: #CAD2D3;
      }
    </style>
    <h1><img src="https://i.ibb.co/cvHLWfN/transparent-aws-logo.png" alt="transparent-aws-logo" width="189" height="69" border="0" />&nbsp; &nbsp;<span style="color: #000000;"><strong>AWS BACKUP STATUS</strong></span></h1>
    <p>The following report was run on $(get-date).</p>
"@


$Header = @"
<style>
TABLE {border-width: 2px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 2px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 2px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@

Get-BAKBackupJobList -ByCreatedAfter $date | Select-Object -Property @{Label = 'VolumeId'; Expression = { $_.ResourceArn.substring($_.ResourceArn.length - 21) } }, @{Label = 'BackupSizeInGB'; Expression = { [int]($_.BackupSizeInBytes / 1GB) } }, BackupJobId, CreationDate, CompletionDate, State |
ConvertTo-Html -Head $Header -Body $Body | ForEach-Object {
    $PSItem -replace "<td>COMPLETED</td>", "<td style='background-color:#7CFC00'>COMPLETED</td>" } | out-file "E:\Report\AWSBackup\Report_AWSBackup-$date.html"

巴斯托斯AWS。

4

1 回答 1

0

更新 :

我通过创建的 PSCustomObject 找到了我想要的: 它正在工作!

代码:

# AWS Credentials
Set-AWSCredential -ProfileName XXXX
Set-DefaultAWSRegion -Region XXXXX

$date = (get-date -Format "MM-dd-yyyy" (Get-Date).AddDays(-1)) #Last day


$Body = @"
<style>
      body {
      background-color: #CAD2D3;
      }
    </style>
    <h1><img src="https://i.ibb.co/cvHLWfN/transparent-aws-logo.png" alt="transparent-aws-logo" width="189" height="69" border="0" />&nbsp; &nbsp;<span style="color: #000000;"><strong>AWS BACKUP STATUS</strong></span></h1>
    <p>The following report was run on $(get-date).</p>
"@


$Header = @"
<style>
TABLE {border-width: 2px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 2px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 2px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@

$var = Get-BAKBackupJobList -ByBackupVaultName daily-ec2-ami | Select-Object -Property @{Label = 'InstanceId'; Expression = { $_.ResourceArn.substring($_.ResourceArn.length - 19) } }, @{Label = 'BackupSizeInGB'; Expression = { [int]($_.BackupSizeInBytes / 1GB) } }, BackupJobId, CreationDate, CompletionDate, State
$vmobjects = @()
foreach ($row in $var)
{
    $ec2id = $row.InstanceId
    $object = [PSCustomObject][Ordered] @{
        Name = Get-EC2Tag | ? { $_.ResourceID -eq "$ec2id"} | ? { $_.key -eq "Name" } | select -expand Value
        Application = Get-EC2Tag | ? { $_.ResourceID -eq "$ec2id"} | ? { $_.key -eq "Application" } | select -expand Value
        InstanceId = $row.InstanceId
        BackupSizeInGB = $row.BackupSizeInGB
        CreationDate = $row.CreationDate
        CompletionDate = $row.CreationDate
        State = $row.State

    }
    $vmobjects += $object
}

$vmobjects | ConvertTo-Html -Head $Header -Body $Body | ForEach-Object {
    $PSItem -replace "<td>COMPLETED</td>", "<td style='background-color:#7CFC00'>COMPLETED</td>" } | out-file "E:\Report\AWSBackup\Report_AWSBackup-$date.html
于 2020-10-09T12:48:25.910 回答