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 } }