title: MS Graph API access client tenant with partner credentials
body: <p>I use the following PowerShell code to access MS Graph API.    </p>
  
  <pre><code>Import-Module MSOnline
  $User = "UserName"
  $Password = "Password"
  $TenantName = "tenantname.onmicrosoft.com"
  $clientId = "clientId"
  $authority = "https://login.microsoftonline.com/$TenantName"
  $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
  $AADCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" -ArgumentList $AdminUser, $Password
  $resourceAppIdURI = "https://graph.microsoft.com"
  $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$AADCredential)
  
  $authHeader = @{
      'Content-Type'='application\json'
      'Authorization'=$authResult.CreateAuthorizationHeader()
  }
  $uri = "https://graph.microsoft.com/beta/$TenantName/reports/getEmailActivityUserDetail(period='D7')"
  Invoke-RestMethod -Uri $uri -Method Get -Headers $authHeader
  </code></pre>
  
  <p>It works fine when the user and tenant agree. What I would like to do is access our client tenants using an admin with delegated permissions. I've set the app to have Pre-consent permissions, which according to <a href="https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider" rel="nofollow noreferrer">https://developer.microsoft.com/en-us/graph/docs/concepts/auth_cloudsolutionprovider</a> should also allow the behaviour I am after. However, when I run the code with a partner admin credentials and client tenantname, I receive a 400 bad request error. What step am I missing here?</p>