Check if the server is hosted on Google Cloud or AWS

  • AWS
    curl -Lso /dev/null http://169.254.169.254/latest/meta-data && echo "Definitely AWS"
    if ((IWR -URI http://169.254.169.254/latest/meta-data -UseBasicParsing) -ne $null) { echo "Definitely AWS" }
  • GCN
    curl -Lso /dev/null -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/ && echo "Definitely GC"

    PowerShell 3.0 or newer is required to send custom headers

    if ((IWR -URI "http://metadata.google.internal/computeMetadata/v1/" -Headers @{"Metadata-Flavor"="Google"} -UseBasicParsing) -ne $null) { echo "Definitely GC" }