ps/Modules/Alkami.PowerShell.Common/Public/Get-CurrentInstance.ps1

35 lines
814 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-CurrentInstance {
<#
.SYNOPSIS
Gets the Current Instance Object
#>
[CmdletBinding()]
Param()
$logLead = (Get-LogLeadName)
Import-AWSModule # EC2
if ( (Test-IsAws) -eq $false ) {
Write-Warning "$logLead : This function can only be executed on an AWS server"
return $null
}
try {
$instance = Get-EC2Instance -InstanceId (Get-CurrentInstanceId)
if (($null -eq $instance) -or ($null -eq $instance.Instances)) {
Write-Warning "$logLead : The Instance Was Null!"
return $null
}
return (([array]$instance.Instances) | Select-Object -First 1)
} catch {
Write-Warning ("$logLead : Could Not Pull Current Instance Due to Error: {0}" -f $_.Exception.Message)
return $null
}
}