title: Use the AZ module in a non-interactive environment?
body: <p>I'm hoping to be able to use the <code>Az</code> module to retrieve a secret from an Azure key vault, for use with a PowerShell script that has been deployed to a server and is run daily by Windows Task Scheduler.</p>
  <p>Initially, I needed to follow the oauth (a guess) process:</p>
  <pre><code>Connect-AzAccount -Tenant '69a29f45-...'
  </code></pre>
  <p>Which redirects to <a href="https://login.microsoftonline.com/..." rel="nofollow noreferrer">https://login.microsoftonline.com/...</a>, asking you to choose an account:</p>
  <p><a href="https://i.stack.imgur.com/6whBV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6whBV.png" alt="enter image description here" /></a></p>
  <p>eventually, it indicates success:</p>
  <pre><code>Authentication complete. You can return to the application. Feel free to close this browser tab.
  </code></pre>
  <p>After this has been completed, the script that retrieves the secret works as expected:</p>
  <pre><code>...
  $AccessToken = Get-AzKeyVaultSecret -VaultName 'MyVault' -Name 'MySecret' | Select-Object -ExpandProperty SecretValue | ConvertFrom-SecureString -AsPlainText
  ...
  </code></pre>
  <p>I'm concerned that the token will expire, causing my script to fail.</p>
  <p>The SharePoint module (<code>Pnp.PowerShell</code>) can <a href="https://github.com/pnp/PnP-PowerShell/wiki/How-to-use-the-Windows-Credential-Manager-to-ease-authentication-with-PnP-PowerShell" rel="nofollow noreferrer">make use of a credential stored in Windows Credential Manager</a>.  Can the <code>Az</code> module do so as well?</p>
  <p>If not, is there another way to handle this authentication process without interaction?</p>