-
Notifications
You must be signed in to change notification settings - Fork 14
/
Get-Ami.ps1
47 lines (42 loc) · 2.79 KB
/
Get-Ami.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-Ami
{
<#
.Synopsis
Gets Amazon Machine Images
.Description
Gets the available Amazon Machine Images
.Example
Get-Ami
.Link
Add-EC2
#>
[CmdletBinding(DefaultParameterSetName='Keyword')]
[OutputType([PSObject])]
param(
# The exact name of the AMI image
[Parameter(Mandatory=$true,Position=0,ParameterSetName='Name')]
[string]$Name,
# A keyword to look for in AMI images
[Parameter(Mandatory=$true,Position=0,ParameterSetName='Keyword')]
[string]$Keyword,
# If set, gets all available AMIs
[Parameter(Mandatory=$true,Position=0,ParameterSetName='All')]
[Switch]$All
)
process {
if (-not $script:CachedImageData) {
$script:CachedImageData = $AwsConnections.EC2.DescribeImages((New-Object Amazon.EC2.Model.DescribeImagesRequest)).DescribeImagesResult.Image
}
$script:CachedImageData |
Where-Object {
if ($Name) {
$_.Name -eq $name
} elseif ($Keyword) {
$_.Name -like "*$keyword*" -or $_.Description -like "*$Keyword*"
} else {
$true
}
} |
Sort-Object Platform -Descending
}
}