title: How can I connect to Exchange online (connect-exopssession) with credentials and no form?
body: <p>I've tried a couple of variants of this (all 3 shown below). With this code, if I specify a value for  <code>-UserPrincipalName</code> a form will pop up quickly and disappear, fast enough to where only the form borders are rendered. If I do not specify a value for <code>-UserPrincipalName</code>, that same form opens and asks for me to sign in with my email address. The third option I tried was with <code>-Credential</code> and a credential object, I get the error:</p>
  
  <blockquote>
    <p><em>"New-ExoPSSession : missing_federation_metadata_url: Federation Metadata Url is missing for federated user. This user type is
    unsupported."</em> .</p>
  </blockquote>
  
  <p>My end goal here is to authenticate without the form popping up so I can run some code with a scheduled task, which right now will not work because of the form and interactive mode. I can use creds, NO MFA and need to supress this form
  somehow.</p>
  
  <p>How can I connect to Exchange Online without this form appearing? Is there a way to use <code>New-PSsession</code> or <code>Import-PSsession</code>, or to wrap the <code>New-ExoPSSession</code> in something that prevents it from opening a form?</p>
  
  <p>(Also, we need an "exchange-online" tag added, I don't have enough reputation to do so)</p>
  
  <p><a href="https://i.stack.imgur.com/JShWB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JShWB.jpg" alt="enter image description here"></a></p>
  
  <pre><code>[string] $ConnectionUri = "https://outlook.office365.com/PowerShell-LiveId"
  [string] $AzureADAuthorizationEndpointUri = 'https://login.windows.net/common'       
  [System.Management.Automation.Remoting.PSSessionOption] $PSSessionOption = $null
  [switch] $BypassMailboxAnchoring = $false
  [string] $DelegatedOrganization = ''
  
  
  $PSSession = New-ExoPSSession -UserPrincipalName "xxx@xxx.xxx" -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization
  
  $PSSession = New-ExoPSSession -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization
  
  $user = "xxx@xxx.xxx";
  $password = ConvertTo-SecureString "xxxx" -AsPlainText -Force;
  $creds = New-Object System.Management.Automation.PSCredential -ArgumentList ($user, $password)
  $PSSession = New-ExoPSSession -UserPrincipalName "xxx@xxx.xxx" -ConnectionUri $ConnectionUri -AzureADAuthorizationEndpointUri $AzureADAuthorizationEndpointUri -Credential $creds -PSSessionOption $PSSessionOption -BypassMailboxAnchoring:$BypassMailboxAnchoring -DelegatedOrg $DelegatedOrganization
  </code></pre>