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

35 lines
858 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-CurrentInstanceId {
<#
.SYNOPSIS
Gets the Current Instance ID
#>
[CmdletBinding()]
[OutputType([System.String])]
Param()
$logLead = (Get-LogLeadName);
$endpoint = "/meta-data/instance-id"
if ( (Test-IsAws) -eq $false ) {
Write-Warning "$logLead : This function can only be executed on an AWS server"
return $null
}
try {
$instanceId = (Get-InstanceMetadata -Endpoint $endpoint).Content
if ($null -eq $instanceId) {
Write-Warning ("$logLead : Instance ID Came Back Null")
} else {
Write-Verbose ("$logLead : Instance ID Read as {0}" -f $instanceId)
}
return $instanceId
} catch {
Write-Warning ("$logLead : AWS MetaData Check Returned Error: {0}" -f $_.Exception.Message)
return $null
}
}