ps/Modules/Alkami.PowerShell.Configuration/Public/Test-IsAws.ps1
2023-05-30 22:51:22 -07:00

29 lines
865 B
PowerShell

Function Test-IsAws {
<#
.SYNOPSIS
Returns $true if in AWS (based on meta-data endpoint check) and $false if not
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
Param()
$endpoint = "/meta-data/hostname"
# Try reading the metadata endpoint
try {
$awsCheck = (Get-InstanceMetadata -Endpoint $endpoint)
if ($null -ne $awsCheck.Content) {
return $true
}
} catch {
Write-Verbose ("$logLead : AWS Endpoint Check Returned Error: {0}" -f $_.Exception.Message)
}
# Query OS WMI Information
$organizationResult = (Get-CIMInstance -ClassName Win32_OperatingSystem -Namespace "root\CIMV2" `
-Property Organization -ErrorAction SilentlyContinue).Organization
return ($organizationResult -match "amazon")
}
Set-Alias IsAws Test-IsAws -Force -Scope:Global