PowerShell: Query Google Account Using GAM

$emailAddress='someone@yourcompany.com'
$field='accounts:last_login_time'

function getGamUser{
    param(
        $emailAddress,
        $field
    )

    $result=try{gam report users user $emailAddress}catch{}
    if($result){
        $headers=$result[0] -split ','
        $index=$headers.IndexOf($field)
        return ($result[1] -split ',')[$index]
    }else{
        write-warning "$emailAddress field $field has not matched anything"
        return $null
    }
}

getGamUser $emailAddress $field

Leave a Reply

Your email address will not be published. Required fields are marked *