ps/Modules/Alkami.PowerShell.Common/Public/Get-AvailabilityZone.ps1
2023-05-30 22:51:22 -07:00

33 lines
752 B
PowerShell

function Get-AvailabilityZone {
<#
.SYNOPSIS
Returns the availability zone name of a server in AWS, or otherwise $null.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[string]$ComputerName = "localhost"
)
$logLead = (Get-LogLeadName)
Import-AWSModule # EC2
if($ComputerName -eq "localhost" -or $ComputerName -eq "." -or $ComputerName -eq (hostname)) {
return Get-CurrentInstanceAvailabilityZone
} else {
$filter =@(
@{
name='tag:alk:hostname';
values="$ComputerName"
}
)
Write-Verbose "$logLead : Getting instance"
$instance = (Get-EC2Instance -Filter $filter).Instances | Select-Object -First 1
$placementData = $instance.Placement
$az = $placementData.AvailabilityZone
return $az
}
}