Any one know how to pass OAuth Token and UPN name in PSCredential Object.

Hi Bro.

This is MY Full Working Code

Bro , How could i send my certificate file in reddit.

And also do you want credential for azure portal of mine

#App-only Authentication

#===========================

#this is the Exchange online endpoint

$resourceUrl = "https://outlook.office365.com/"
$TenantId = "3cfc39d0-a175-4f14-b570-3b909937f2e5"
$CertificateTUmprint = "CEF4ADCC9CB9E0DC9D9C0B55DBC698164023CBCD"
$authority =  "https://login.microsoftonline.com/3cfc39d0-a175-4f14-b570-3b909937f2e5"
$clientId = "7159b04d-c5eb-4dd1-b5a3-2c0806f307cf"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2('D:\Certificate.pfx','Sk@cse10','DefaultKeySet')

#Getting Oauth Token Using Certificate and client id
$response = Get-ADALToken -Resource $resourceUrl -ClientId $clientId -Authority $authority -ClientAssertionCertificate $cert
$Token = $response.AccessToken
#Write-Output $response

$tokenValue = ConvertTo-SecureString "Bearer $($response.AccessToken)" -AsPlainText -Force
$AppCredential = New-Object System.Management.Automation.PSCredential ('[email protected]',$tokenValue)

Connect-ExchangeOnline -Credential $AppCredential
Get-Mailbox
Disconnect-ExchangeOnline
/r/PowerShell Thread Parent