35 lines
858 B
PowerShell
35 lines
858 B
PowerShell
|
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
|
||
|
}
|
||
|
}
|