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" }

Show permissions for a file and all parent folders

function namei {
    If ( $args[0] -eq $null ) {
        $path = ($pwd).Path
    } Else {
        $path = $args[0]
    }
    If ( -not (Test-Path -Path $path) ) {
        echo "Path does not exist"
        return
    }
    While ( $path -ne "" ) {
        $acl = Get-ACL -Path $path
        echo $path "`r`n"
        (
            $acl | Select -Property Owner,Group | FL | Out-String
        ).Trim()
        $acl | Select -Expand Access | Select -Property FileSystemRights,AccessControlType,IdentityReference,IsInherited | FT
        $path = $path | Split-Path
    }
}
namei C:\Windows