0
한 지역에서 다른 지역으로 AWS의 볼륨 스냅 샷을 복사하는 Powershell 스크립트를 설정하려고합니다. 나는 아래의 스크립트가 작동해야한다고 생각하지만 필자의 psobject $ Snapshots가 소스 영역의 일치 항목을 제대로 채우지 못하고 있다는 몰래 의심 스럽습니다. PS noob의 종류, 누구든지 배열 채우기 문제를 해결하는 방법을 알려주거나 내 스크립트에서 명백한 실수를 발견 할 수 있습니까? 설명서에서이 작동합니다 :Powershell에서 psobject 배열의 내용을 검사하려면 어떻게합니까?
# 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
}
감사하지만, 쉘에서 직접 실행할 때 스냅 샷 복사 foreach 루프 중 하나와 함께 작동하지 않습니다 .. 내가 PowerShell에서이 문제를 해결하는 방법을 모른다 - 방법은 수 $ Snapshots 배열의 내용을 검사하여 제대로 채워 졌는지 확인합니다. – fergie348
나는 Powershell ISE에 이런 식으로로드하고'<# (code lines) #>'을 사용하여 모든 것을 주석 처리합니다. 그런 다음 원하는 파일을 검사합니다. ISE에 내장 된 디버거 또는 타사 도구를 사용하여 디버깅 할 수도 있습니다. – Eris