Private/ConfirmGoogleComputeVM.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function ConfirmGoogleComputeVM { $GoogleComputeMetadataUrl = "http://metadata.google.internal/computeMetadata/v1/" try { #$Result = (Invoke-WebRequest -Uri $Url -UseBasicParsing -DisableKeepAlive -Method Head).StatusCode $HTTP_Request = [System.Net.WebRequest]::Create($GoogleComputeMetadataUrl) $HTTP_Response = $HTTP_Request.GetResponse() $Result = $HTTP_Response.StatusCode } catch [Net.WebException] { $Result = [int]$_.Exception.Response.StatusCode } if ($Result -eq 0) { $False } else { $True } } |