title: Powershell office 365 delegated admin issues connecting to tenants
body: <p>I have reviewed the documentation from microsoft and alot of examples but for some reason connecting to a tenant using our admin privs will not connect:</p>
  
  <pre><code>$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid?DelegatedOrg=xxxxx.onmicrosoft.com -Credential $UserCredential -Authentication Basic –AllowRedirection
  </code></pre>
  
  <p>I have also tried substituting the domain name to outlook.office365.com as well</p>
  
  <p>The error returned is:</p>
  
  <blockquote>
    <p>New-PSSession : [ps.outlook.com] Processing data from remote server
    ps.outlook.com failed with the following error message: 
    [AuthZRequestId=477bd052-617e-4e8c-aee9-dxxxxxxxx][FailureCategory=AuthZ-CmdletAccessDeniedException]
    The operation couldn't be performed because 
    'xxxxx.onmicrosoft.com\xxxxxxadmin@xxxxx.onmicrosoft.com' couldn't be
    found. For more information, see the about_Remote_Troubleshooting Help
    topic.</p>
  </blockquote>
  
  <p>I have ensured that the deligated admin account is:</p>
  
  <ul>
  <li>Global administrator</li>
  <li>Administrative access to companies you support: Yes / Full admin</li>
  </ul>
  
  <p>I have also tried to google up that error, not alot of information.  As well this site: <a href="https://gcits.com/knowledge-base/" rel="nofollow noreferrer">https://gcits.com/knowledge-base/</a> has a tone of examples about this using those examples results in basically the same hang up.</p>
  
  <p>I can however connect and issue the "$customers = Get-MsolPartnerContract -All" and view all the tenants.</p>
  
  <p>Any ideas?</p>
  
  <p>** UPDATE ** code is below as per request. Thanks again!</p>
  
  <pre>
  $credential = Get-Credential
  Connect-MsolService -Credential $credential
  $customers = Get-MsolPartnerContract -All
  Write-Host "Found $($customers.Count) customers for $((Get-MsolCompanyInformation).displayname)."
  
  foreach ($customer in $customers) {
  
      Write-Host "Connecting to: $($customer.name)" -ForegroundColor Yellow
      $InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where-Object {$_.IsInitial}
  
  
      $DelegatedOrgURL = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name
      $EXODS = New-PSSession -ConnectionUri $DelegatedOrgURL -Credential $credential -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection
      Import-PSSession $EXODS -CommandName Get-CASMailbox, Set-CasMailbox, Get-Casmailboxplan, set-casmailboxplan
       </pre>