我正在尝试设置一个 Powershell 脚本,将 AWS 中的卷快照从一个区域复制到另一个区域。我认为下面的脚本应该可以工作,但我偷偷怀疑我的 psobject $Snapshots 没有正确填充来自我的源区域的匹配项。有点像 PS 菜鸟,谁能告诉我如何解决阵列填充问题或在我的脚本中发现任何明显的错误?从文档中,这应该有效:
# Adds snap-ins to the current powershell session for Powershell for Amazon Web Services.
if (-not (Get-Module AWSPowerShell -ErrorAction SilentlyContinue))
{Import-Module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1" > $null
}
Set-DefaultAWSRegion us-west-1
Creates the filter for qualifying snapshots
$Filter = (New-Object Amazon.EC2.Model.Filter).WithName("tag:SnapStatus").WithValue("SnapshotEBSEnabled")
# Loads the qualifying snapshots into an array of snapshots
$Snapshots = Get-EC2Snapshot -Region us-east-1 -Filter $Filter
# Loops through the snapshot objects and copies them from us-east-1 to us-west-1
foreach ($Snapshot in $Snapshots)
{$Snapshot | Where-Object {$_.Description -eq "SnapshotEBSEnabled"} | Copy-EC2Snapshot -SourceRegion us-east-1 -SourceSnapshotId $Snapshot.SnapshotId -Description "SnapshotEBSEnabled" -Region us-west-1
}