Updates to the Exch-Relaxation PowerShell Module to assist PowerShell Core, Azure Cloud Shell and extra ADAL integration choices

Updates to the Exch-Relaxation PowerShell Module to assist PowerShell Core, Azure Cloud Shell and extra ADAL integration choices I’ve had a while just lately to do some a lot wanted updates to my Exch-Relaxation module so it now helps each Azure Cloud Shell and PowerShell Core on Linux (examined on RHEL,CentOS, Debian and Ubuntu). So now you’ll be able to logon to an Workplace365 Mailbox utilizing this Module with Powershell on Linux and ship E mail or a Skype for Enterprise Message or do some mailbox reporting eg

The necessities on Linux is you have to be utilizing the most recent model of PowerShell core put in as per https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6 .This ensures that each one the required .web Core libraries will likely be out there as older model of .Internet core did not have a number of the libraries I am utilizing and I did not need to backport for older variations.  Additionally as a result of there aren’t any Linux kinds to work together with for authentication you have to move within the credentials to make use of through a PSCredential and the code will use the password grant to get the Token eg

$cred = Get-Credential -UserName [email protected]
connect-exrmailbox -MailboxName [email protected] -Credential $Cred

Azure Cloud Shell

As Cloud Shell is a browser based mostly model of  PowerShell core operating on Linux the identical connection technique of utilizing the credentials as above is required.

ADAL Integration

I’ve additionally added full integration with the ADAL library for authentication so along with the native dependency free script strategies the module now distributes the ADAL libraries and helps Authentication utilizing that library in addition to Token refreshes for scripts that run over an hour and many others (utilizing Acquiretokenasync within the ADAL). This helps the next eventualities corresponding to

To make use of the ADAL libraries for Logon use the next 

connect-exrmailbox -MailboxName [email protected] -useADAL

To make use of the By no means Immediate to make use of the ADAL Cache
connect-exrmailbox -MailboxName [email protected] -useADAL -Immediate By no means
For connecting utilizing the presently logged on credentials use
connect-exrmailbox -MailboxName [email protected] -useADAL -useLoggedOnCredentials -AADUserName [email protected]

(The -AADUserName variable is elective however normally required learn the GitHub hyperlink within the second bullet level)

For many who need to do one thing simular and are utilizing EWS you will want one thing like the next to get the AccessToken utilizing ADAL in a traditional PowerShell Script.

    $ClientId = "d3590ed6-52b3-4102-aeff-aad2292ab01c"
$ResourceURI = "https://outlook.workplace365.com"
$EndpointUri = 'https://login.microsoftonline.com/frequent'
$Context = New-Object Microsoft.IdentityModel.Shoppers.ActiveDirectory.AuthenticationContext($EndpointUri)
$AADCredential = New-Object "Microsoft.IdentityModel.Shoppers.ActiveDirectory.UserCredential" -ArgumentList "[email protected]"
$authResult = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions]::AcquireTokenAsync($Context, $ResourceURI, $ClientId, $AADcredential)
if ($authResult.Consequence.AccessToken) {
$token = $authResult.Consequence
}
elseif ($authResult.Exception) {
throw "An error occured getting entry token: $($authResult.Exception.InnerException)"
}
return $token

This additionally goes together with assist for utilizing the Module in an Azure Runbook which was added final month.

The Exch-REST Module is offered from the PowerShell Gallery https://www.powershellgallery.com/packages/Exch-Relaxation and GitHub https://github.com/gscales/Exch-Relaxation

An enormous thankyou to all these individuals who offered suggestions on utilizing the module hopefully these upgrades make it simpler to make use of in additional eventualities.
Rent me – If you want to do one thing just like this or anything you see on my weblog I am presently out there to assist with any Workplace365,Microsoft Groups, Change or Energetic Listing associated improvement work or scripting, please contact me at [email protected] (nothing too large or small).
Tags:

Related Posts

Leave a Reply