title: How to detect if Azure Powershell session has expired?
body: <p>I'm writing an Azure PowerShell script and to login to Azure I call <code>Add-AzureAccount</code> which will popup a browser login window. </p>
  
  <p>I'm wondering what's the best way to check if the authentication credentials have expired or not and thus if I should call <code>Add-AzureAccount</code> again?  </p>
  
  <p>What I now do is that I just call <code>Get-AzureVM</code> and see if <code>$?</code> equals to <code>$False</code>. Sounds a bit hackish to me, but seems to work. And does it still work if the subscription doesn't have any virtual machines deployed? </p>